From b86812f966343c22eed685840a0104444864a4d6 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 5 Feb 2024 13:46:04 +0200 Subject: [PATCH 001/490] Add config files --- .editorconfig | 24 ++++++++ phpcs.xml.dist | 149 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 173 insertions(+) create mode 100644 .editorconfig create mode 100644 phpcs.xml.dist diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..c6f3cf495 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,24 @@ +# This file is for unifying the coding style for different editors and IDEs +# editorconfig.org + +# WordPress Coding Standards +# https://make.wordpress.org/core/handbook/coding-standards/ + +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +indent_style = tab + +[*.yml] +indent_style = space +indent_size = 2 + +[*.md] +trim_trailing_whitespace = false + +[{*.txt,wp-config-sample.php}] +end_of_line = crlf diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 000000000..9ca2d44fb --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,149 @@ + + + + A custom set of rules to check for the ProgressPlanner project + + + + . + + + /vendor/* + + + /node_modules/* + + + /coverage/* + + + *.min.js + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + /tests/bootstrap\.php$ + + From f000c1ec5823119edd30bdcda6c2e1b771afac98 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 5 Feb 2024 13:47:09 +0200 Subject: [PATCH 002/490] initial structure for stats --- includes/autoload.php | 31 +++++++++++++++++++++ includes/class-progress-planner.php | 36 +++++++++++++++++++++++++ includes/class-stats.php | 42 +++++++++++++++++++++++++++++ includes/stats/class-stat-posts.php | 23 ++++++++++++++++ includes/stats/class-stat.php | 23 ++++++++++++++++ progress-planner.php | 10 +++++++ 6 files changed, 165 insertions(+) create mode 100644 includes/autoload.php create mode 100644 includes/class-progress-planner.php create mode 100644 includes/class-stats.php create mode 100644 includes/stats/class-stat-posts.php create mode 100644 includes/stats/class-stat.php create mode 100644 progress-planner.php diff --git a/includes/autoload.php b/includes/autoload.php new file mode 100644 index 000000000..55b102268 --- /dev/null +++ b/includes/autoload.php @@ -0,0 +1,31 @@ +stats = new Stats(); + $this->register_stats(); + } + + /** + * Register the individual stats. + */ + private function register_stats() { + $this->stats->add_stat( 'posts', new Stats\Stat_Posts() ); + } +} diff --git a/includes/class-stats.php b/includes/class-stats.php new file mode 100644 index 000000000..b31d0a8dd --- /dev/null +++ b/includes/class-stats.php @@ -0,0 +1,42 @@ +stats[ $id ] = $stat; + } + + /** + * Get the individual stats. + * + * @return array + */ + public function get_stats() { + return $this->stats; + } +} diff --git a/includes/stats/class-stat-posts.php b/includes/stats/class-stat-posts.php new file mode 100644 index 000000000..b2a96c9de --- /dev/null +++ b/includes/stats/class-stat-posts.php @@ -0,0 +1,23 @@ + (array) wp_count_posts(), + ); + } +} diff --git a/includes/stats/class-stat.php b/includes/stats/class-stat.php new file mode 100644 index 000000000..f0c211a3c --- /dev/null +++ b/includes/stats/class-stat.php @@ -0,0 +1,23 @@ + Date: Mon, 5 Feb 2024 14:24:29 +0200 Subject: [PATCH 003/490] get posts stats for day, week, month, year --- includes/stats/class-stat-posts.php | 49 ++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/includes/stats/class-stat-posts.php b/includes/stats/class-stat-posts.php index b2a96c9de..65fcc3269 100644 --- a/includes/stats/class-stat-posts.php +++ b/includes/stats/class-stat-posts.php @@ -17,7 +17,54 @@ class Stat_Posts extends Stat { */ public function get_data() { return array( - 'counts' => (array) wp_count_posts(), + 'total' => (array) wp_count_posts(), + 'day' => $this->get_posts_stats_by_date( [ + [ + 'after' => 'today', + 'inclusive' => true, + ], + ] ), + 'week' => $this->get_posts_stats_by_date( [ + [ + 'after' => '-1 week', + 'inclusive' => true, + ], + ] ), + 'month' => $this->get_posts_stats_by_date( [ + [ + 'after' => '-1 month', + 'inclusive' => true, + ], + ] ), + 'year' => $this->get_posts_stats_by_date( [ + [ + 'after' => '-1 year', + 'inclusive' => true, + ], + ] ), + ); + } + + /** + * Get posts by dates. + * + * @param array $date_query The date query. + * @return array + */ + private function get_posts_stats_by_date( $date_query ) { + $args = array( + 'posts_per_page' => 1000, + 'post_type' => 'post', + 'post_status' => 'publish', + 'date_query' => $date_query, + 'suppress_filters' => false, + ); + + $posts = get_posts( $args ); + + return array( + 'count' => count( $posts ), + 'post_ids' => wp_list_pluck( $posts, 'ID' ), ); } } From 504c7f77e83d482de4d618539c16e23a8b5efacd Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 5 Feb 2024 14:37:00 +0200 Subject: [PATCH 004/490] add more methods to get stats --- includes/class-progress-planner.php | 9 +++++++++ includes/class-stats.php | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/includes/class-progress-planner.php b/includes/class-progress-planner.php index c132941ba..419cd66b3 100644 --- a/includes/class-progress-planner.php +++ b/includes/class-progress-planner.php @@ -33,4 +33,13 @@ public function __construct() { private function register_stats() { $this->stats->add_stat( 'posts', new Stats\Stat_Posts() ); } + + /** + * Get the stats object. + * + * @return \ProgressPlanner\Stats + */ + public function get_stats() { + return $this->stats; + } } diff --git a/includes/class-stats.php b/includes/class-stats.php index b31d0a8dd..103f8acd8 100644 --- a/includes/class-stats.php +++ b/includes/class-stats.php @@ -32,11 +32,21 @@ public function add_stat( $id, $stat ) { } /** - * Get the individual stats. + * Get all stats. * * @return array */ - public function get_stats() { + public function get_all_stats() { return $this->stats; } + + /** + * Get an individual stat. + * + * @param string $id The ID of the stat. + * @return Stat + */ + public function get_stat( $id ) { + return $this->stats[ $id ]; + } } From dde0f81ecfc1795f308eb245357c57ceb74964f3 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 6 Feb 2024 09:50:25 +0200 Subject: [PATCH 005/490] Add post_type to post stats --- includes/stats/class-stat-posts.php | 22 +++++++++++++++++++--- progress-planner.php | 2 +- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/includes/stats/class-stat-posts.php b/includes/stats/class-stat-posts.php index 65fcc3269..18c8f2474 100644 --- a/includes/stats/class-stat-posts.php +++ b/includes/stats/class-stat-posts.php @@ -10,6 +10,22 @@ */ class Stat_Posts extends Stat { + /** + * The post-type for this stat. + * + * @var string + */ + protected $post_type = 'post'; + + /** + * Set the post-type for this stat. + * + * @param string $post_type The post-type. + */ + public function set_post_type( $post_type ) { + $this->post_type = $post_type; + } + /** * Get the stat data. * @@ -17,7 +33,7 @@ class Stat_Posts extends Stat { */ public function get_data() { return array( - 'total' => (array) wp_count_posts(), + 'total' => (array) \wp_count_posts(), 'day' => $this->get_posts_stats_by_date( [ [ 'after' => 'today', @@ -54,7 +70,7 @@ public function get_data() { private function get_posts_stats_by_date( $date_query ) { $args = array( 'posts_per_page' => 1000, - 'post_type' => 'post', + 'post_type' => $this->post_type, 'post_status' => 'publish', 'date_query' => $date_query, 'suppress_filters' => false, @@ -64,7 +80,7 @@ private function get_posts_stats_by_date( $date_query ) { return array( 'count' => count( $posts ), - 'post_ids' => wp_list_pluck( $posts, 'ID' ), + 'post_ids' => \wp_list_pluck( $posts, 'ID' ), ); } } diff --git a/progress-planner.php b/progress-planner.php index 1169b5e6d..dd5e9e5df 100644 --- a/progress-planner.php +++ b/progress-planner.php @@ -7,4 +7,4 @@ require_once PROGRESS_PLANNER_DIR . '/includes/autoload.php'; -new \ProgressPlanner\Progress_Planner(); \ No newline at end of file +new \ProgressPlanner\Progress_Planner(); From f00deb1f72fe77955f4f4847f76c4f90c4054311 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 6 Feb 2024 09:55:46 +0200 Subject: [PATCH 006/490] Add stats for terms --- includes/stats/class-stat-terms.php | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 includes/stats/class-stat-terms.php diff --git a/includes/stats/class-stat-terms.php b/includes/stats/class-stat-terms.php new file mode 100644 index 000000000..7546df871 --- /dev/null +++ b/includes/stats/class-stat-terms.php @@ -0,0 +1,39 @@ +taxonomy = $taxonomy; + } + + /** + * Get the stat data. + * + * @return array + */ + public function get_data() { + return array( + 'total' => (array) \wp_count_terms( [ 'taxonomy' => $this->taxonomy ] ), + ); + } +} From 0998ab7807eaa7cbbd0dcfcd65ac6dffaa4d9130 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 6 Feb 2024 10:11:51 +0200 Subject: [PATCH 007/490] Add period arg to get_data method --- includes/stats/class-stat-posts.php | 76 ++++++++++++++++++----------- includes/stats/class-stat-terms.php | 2 +- includes/stats/class-stat.php | 4 +- 3 files changed, 52 insertions(+), 30 deletions(-) diff --git a/includes/stats/class-stat-posts.php b/includes/stats/class-stat-posts.php index 18c8f2474..bcc19ece2 100644 --- a/includes/stats/class-stat-posts.php +++ b/includes/stats/class-stat-posts.php @@ -29,36 +29,56 @@ public function set_post_type( $post_type ) { /** * Get the stat data. * + * @param string $period The period to get the data for. + * * @return array */ - public function get_data() { - return array( - 'total' => (array) \wp_count_posts(), - 'day' => $this->get_posts_stats_by_date( [ - [ - 'after' => 'today', - 'inclusive' => true, - ], - ] ), - 'week' => $this->get_posts_stats_by_date( [ - [ - 'after' => '-1 week', - 'inclusive' => true, - ], - ] ), - 'month' => $this->get_posts_stats_by_date( [ - [ - 'after' => '-1 month', - 'inclusive' => true, - ], - ] ), - 'year' => $this->get_posts_stats_by_date( [ - [ - 'after' => '-1 year', - 'inclusive' => true, - ], - ] ), - ); + public function get_data( $period = 'week' ) { + + switch ( $period ) { + case 'all': + return (array) \wp_count_posts( $this->post_type ); + + case 'day': + return $this->get_posts_stats_by_date( [ + [ + 'after' => 'today', + 'inclusive' => true, + ], + ] ); + + case 'week': + return $this->get_posts_stats_by_date( [ + [ + 'after' => '-1 week', + 'inclusive' => true, + ], + ] ); + + case 'month': + return $this->get_posts_stats_by_date( [ + [ + 'after' => '-1 month', + 'inclusive' => true, + ], + ] ); + + case 'year': + return $this->get_posts_stats_by_date( [ + [ + 'after' => '-1 year', + 'inclusive' => true, + ], + ] ); + + default: + return $this->get_posts_stats_by_date( [ + [ + 'after' => $period, + 'inclusive' => true, + ], + ] ); + } } /** diff --git a/includes/stats/class-stat-terms.php b/includes/stats/class-stat-terms.php index 7546df871..ecca6e77e 100644 --- a/includes/stats/class-stat-terms.php +++ b/includes/stats/class-stat-terms.php @@ -31,7 +31,7 @@ public function set_taxonomy( $taxonomy ) { * * @return array */ - public function get_data() { + public function get_data( $period = 'week' ) { return array( 'total' => (array) \wp_count_terms( [ 'taxonomy' => $this->taxonomy ] ), ); diff --git a/includes/stats/class-stat.php b/includes/stats/class-stat.php index f0c211a3c..4a2b670ed 100644 --- a/includes/stats/class-stat.php +++ b/includes/stats/class-stat.php @@ -17,7 +17,9 @@ abstract class Stat { /** * Get the stat data. * + * @param string $period The period to get the data for. + * * @return array */ - abstract public function get_data(); + abstract public function get_data( $period = 'week' ); } From e6c1a76630886eff2d2c142856779fabbd2ce744 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 6 Feb 2024 10:11:59 +0200 Subject: [PATCH 008/490] Add stats for words --- includes/stats/class-stat-words.php | 52 +++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 includes/stats/class-stat-words.php diff --git a/includes/stats/class-stat-words.php b/includes/stats/class-stat-words.php new file mode 100644 index 000000000..a569f1abe --- /dev/null +++ b/includes/stats/class-stat-words.php @@ -0,0 +1,52 @@ +get_word_count( $post_type, 'week' ); + } + return $stats; + } + + /** + * Get the word count for a post type. + * + * @param string $post_type The post type. + * @param string $period The period to get the word count for. + * @return int + */ + protected function get_word_count( $post_type, $period ) { + $posts_stats = new Stat_Posts(); + $posts_stats->set_post_type( $post_type ); + $posts_stats_data = $posts_stats->get_data( $period ); + + $word_count = 0; + if ( empty( $posts_stats_data['post_ids'] ) ) { + return 0; + } + foreach ( $posts_stats_data['post_ids'] as $post_id ) { + $post = \get_post( $post_id ); + $word_count += str_word_count( $post->post_content ); + } + return $word_count; + } +} From 8a2115006beb1912e6a8db94f8f30e006b463850 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 6 Feb 2024 10:35:30 +0200 Subject: [PATCH 009/490] Add admin page --- includes/admin/class-page.php | 47 +++++++++++++++++++++++++++++ includes/class-admin.php | 26 ++++++++++++++++ includes/class-progress-planner.php | 8 +++++ views/admin-page.php | 8 +++++ 4 files changed, 89 insertions(+) create mode 100644 includes/admin/class-page.php create mode 100644 includes/class-admin.php create mode 100644 views/admin-page.php diff --git a/includes/admin/class-page.php b/includes/admin/class-page.php new file mode 100644 index 000000000..8a10a6846 --- /dev/null +++ b/includes/admin/class-page.php @@ -0,0 +1,47 @@ +register_hooks(); + } + + /** + * Register the hooks. + */ + private function register_hooks() { + \add_action( 'admin_menu', [ $this, 'add_page' ] ); + } + + /** + * Add the admin page. + */ + public function add_page() { + \add_menu_page( + \esc_html__( 'Progress Planner', 'progress-planner' ), + \esc_html__( 'Progress Planner', 'progress-planner' ), + 'manage_options', + 'progress-planner', + [ $this, 'render_page' ], + 'dashicons-chart-line' + ); + } + + /** + * Render the admin page. + */ + public function render_page() { + include PROGRESS_PLANNER_DIR . '/views/admin-page.php'; + } +} diff --git a/includes/class-admin.php b/includes/class-admin.php new file mode 100644 index 000000000..f4dec52aa --- /dev/null +++ b/includes/class-admin.php @@ -0,0 +1,26 @@ +admin_page = new Admin\Page(); + } +} diff --git a/includes/class-progress-planner.php b/includes/class-progress-planner.php index 419cd66b3..aac1ebc62 100644 --- a/includes/class-progress-planner.php +++ b/includes/class-progress-planner.php @@ -19,10 +19,18 @@ class Progress_Planner { */ private $stats; + /** + * The Admin object. + * + * @var \ProgressPlanner\Admin + */ + private $admin; + /** * Constructor. */ public function __construct() { + $this->admin = new Admin(); $this->stats = new Stats(); $this->register_stats(); } diff --git a/views/admin-page.php b/views/admin-page.php new file mode 100644 index 000000000..2ec923f14 --- /dev/null +++ b/views/admin-page.php @@ -0,0 +1,8 @@ + +

From 9742a7aaf39bcfeafba7a81257f7e0ac6b418cce Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 6 Feb 2024 10:39:06 +0200 Subject: [PATCH 010/490] register stats --- includes/class-progress-planner.php | 8 -------- includes/class-stats.php | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/includes/class-progress-planner.php b/includes/class-progress-planner.php index aac1ebc62..171013caf 100644 --- a/includes/class-progress-planner.php +++ b/includes/class-progress-planner.php @@ -32,14 +32,6 @@ class Progress_Planner { public function __construct() { $this->admin = new Admin(); $this->stats = new Stats(); - $this->register_stats(); - } - - /** - * Register the individual stats. - */ - private function register_stats() { - $this->stats->add_stat( 'posts', new Stats\Stat_Posts() ); } /** diff --git a/includes/class-stats.php b/includes/class-stats.php index 103f8acd8..15656d3de 100644 --- a/includes/class-stats.php +++ b/includes/class-stats.php @@ -21,6 +21,13 @@ class Stats { */ private $stats = array(); + /** + * Constructor. + */ + public function __construct() { + $this->register_stats(); + } + /** * Add a stat to the collection. * @@ -49,4 +56,13 @@ public function get_all_stats() { public function get_stat( $id ) { return $this->stats[ $id ]; } + + /** + * Register the individual stats. + */ + private function register_stats() { + $this->add_stat( 'posts', new Stats\Stat_Posts() ); + $this->add_stat( 'terms', new Stats\Stat_Terms() ); + $this->add_stat( 'words', new Stats\Stat_Words() ); + } } From f049b12a96dba4894d5cf26c04acb773a1dda2b8 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 6 Feb 2024 10:41:18 +0200 Subject: [PATCH 011/490] Make ProgressPlanner a singleton --- includes/class-progress-planner.php | 22 +++++++++++++++++++++- progress-planner.php | 2 +- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/includes/class-progress-planner.php b/includes/class-progress-planner.php index 171013caf..2115b14e3 100644 --- a/includes/class-progress-planner.php +++ b/includes/class-progress-planner.php @@ -12,6 +12,13 @@ */ class Progress_Planner { + /** + * An instance of this class. + * + * @var \ProgressPlanner\Progress_Planner + */ + private static $instance; + /** * The Stats object. * @@ -26,10 +33,23 @@ class Progress_Planner { */ private $admin; + /** + * Get the single instance of this class. + * + * @return \ProgressPlanner\Progress_Planner + */ + public static function get_instance() { + if ( null === self::$instance ) { + self::$instance = new self(); + } + + return self::$instance; + } + /** * Constructor. */ - public function __construct() { + private function __construct() { $this->admin = new Admin(); $this->stats = new Stats(); } diff --git a/progress-planner.php b/progress-planner.php index dd5e9e5df..578cb1961 100644 --- a/progress-planner.php +++ b/progress-planner.php @@ -7,4 +7,4 @@ require_once PROGRESS_PLANNER_DIR . '/includes/autoload.php'; -new \ProgressPlanner\Progress_Planner(); +\ProgressPlanner\Progress_Planner::get_instance(); From fc09cf662ecd9a1904bc8a2cfdbdbabf406a45de Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 6 Feb 2024 11:15:26 +0200 Subject: [PATCH 012/490] it's alive --- includes/stats/class-stat-posts.php | 3 ++ views/admin-page.php | 61 ++++++++++++++++++++++++++++- views/stat.php | 18 +++++++++ 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 views/stat.php diff --git a/includes/stats/class-stat-posts.php b/includes/stats/class-stat-posts.php index bcc19ece2..829fcf8e9 100644 --- a/includes/stats/class-stat-posts.php +++ b/includes/stats/class-stat-posts.php @@ -21,9 +21,12 @@ class Stat_Posts extends Stat { * Set the post-type for this stat. * * @param string $post_type The post-type. + * + * @return Stat_Posts Returns this object to allow chaining methods. */ public function set_post_type( $post_type ) { $this->post_type = $post_type; + return $this; } /** diff --git a/views/admin-page.php b/views/admin-page.php index 2ec923f14..b8c12a97b 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -4,5 +4,64 @@ * * @package ProgressPlanner */ + +$progress_planner = \ProgressPlanner\Progress_Planner::get_instance(); ?> -

+ +
+

+ +

+ + + $post_type_object ) : ?> + public ) : ?> + + +

label ); ?>

+ +

+ get_stats() + ->get_stat( 'posts' ) + ->set_post_type( $post_type ) + ->get_data( 'all' )['publish'] + ) + ); + ?> +

+ + esc_html__( 'Day', 'progress-planner' ), + 'period' => 'day', + 'post_type' => $post_type, + ], + [ + 'label' => esc_html__( 'Week', 'progress-planner' ), + 'period' => 'week', + 'post_type' => $post_type, + ], + [ + 'label' => esc_html__( 'Month', 'progress-planner' ), + 'period' => 'month', + 'post_type' => $post_type, + ], + [ + 'label' => esc_html__( 'Year', 'progress-planner' ), + 'period' => 'year', + 'post_type' => $post_type, + ], + ]; + + foreach ( $lines as $line ) { + include PROGRESS_PLANNER_DIR . '/views/stat.php'; + } + ?> + +
diff --git a/views/stat.php b/views/stat.php new file mode 100644 index 000000000..4fafc70b7 --- /dev/null +++ b/views/stat.php @@ -0,0 +1,18 @@ +%s: %s

', + esc_html( $line['label'] ), + esc_html( + \ProgressPlanner\Progress_Planner::get_instance() + ->get_stats() + ->get_stat( 'posts' ) + ->set_post_type( $line['post_type'] ) + ->get_data( $line['period'] )['count'] + ) +); From e8cf848a2ef9554d8f0f856e2ccd6ae3d2985000 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 6 Feb 2024 11:16:16 +0200 Subject: [PATCH 013/490] rename file --- views/admin-page.php | 2 +- views/{stat.php => stat-posts.php} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename views/{stat.php => stat-posts.php} (100%) diff --git a/views/admin-page.php b/views/admin-page.php index b8c12a97b..d1cf2a2b2 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -60,7 +60,7 @@ ]; foreach ( $lines as $line ) { - include PROGRESS_PLANNER_DIR . '/views/stat.php'; + include PROGRESS_PLANNER_DIR . '/views/stat-posts.php'; } ?> diff --git a/views/stat.php b/views/stat-posts.php similarity index 100% rename from views/stat.php rename to views/stat-posts.php From f2fe3b892646c51517f6277e9beafea50f3833a2 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 6 Feb 2024 11:50:58 +0200 Subject: [PATCH 014/490] Add words stats in posts stats --- includes/class-stats.php | 1 - includes/stats/class-stat-posts.php | 11 ++++-- includes/stats/class-stat-words.php | 52 ----------------------------- 3 files changed, 9 insertions(+), 55 deletions(-) delete mode 100644 includes/stats/class-stat-words.php diff --git a/includes/class-stats.php b/includes/class-stats.php index 15656d3de..0c04fe45d 100644 --- a/includes/class-stats.php +++ b/includes/class-stats.php @@ -63,6 +63,5 @@ public function get_stat( $id ) { private function register_stats() { $this->add_stat( 'posts', new Stats\Stat_Posts() ); $this->add_stat( 'terms', new Stats\Stat_Terms() ); - $this->add_stat( 'words', new Stats\Stat_Words() ); } } diff --git a/includes/stats/class-stat-posts.php b/includes/stats/class-stat-posts.php index 829fcf8e9..981165952 100644 --- a/includes/stats/class-stat-posts.php +++ b/includes/stats/class-stat-posts.php @@ -101,9 +101,16 @@ private function get_posts_stats_by_date( $date_query ) { $posts = get_posts( $args ); + // Get the number of words. + $word_count = 0; + foreach ( $posts as $post ) { + $word_count += str_word_count( $post->post_content ); + } + return array( - 'count' => count( $posts ), - 'post_ids' => \wp_list_pluck( $posts, 'ID' ), + 'count' => count( $posts ), + 'post_ids' => \wp_list_pluck( $posts, 'ID' ), + 'word_count' => $word_count, ); } } diff --git a/includes/stats/class-stat-words.php b/includes/stats/class-stat-words.php deleted file mode 100644 index a569f1abe..000000000 --- a/includes/stats/class-stat-words.php +++ /dev/null @@ -1,52 +0,0 @@ -get_word_count( $post_type, 'week' ); - } - return $stats; - } - - /** - * Get the word count for a post type. - * - * @param string $post_type The post type. - * @param string $period The period to get the word count for. - * @return int - */ - protected function get_word_count( $post_type, $period ) { - $posts_stats = new Stat_Posts(); - $posts_stats->set_post_type( $post_type ); - $posts_stats_data = $posts_stats->get_data( $period ); - - $word_count = 0; - if ( empty( $posts_stats_data['post_ids'] ) ) { - return 0; - } - foreach ( $posts_stats_data['post_ids'] as $post_id ) { - $post = \get_post( $post_id ); - $word_count += str_word_count( $post->post_content ); - } - return $word_count; - } -} From 384a444464381256fda206302ba5adf8d7b573e4 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 6 Feb 2024 11:51:15 +0200 Subject: [PATCH 015/490] Add caching to posts stats --- includes/stats/class-stat-posts.php | 32 +++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/includes/stats/class-stat-posts.php b/includes/stats/class-stat-posts.php index 981165952..215a3e69f 100644 --- a/includes/stats/class-stat-posts.php +++ b/includes/stats/class-stat-posts.php @@ -17,6 +17,13 @@ class Stat_Posts extends Stat { */ protected $post_type = 'post'; + /** + * Static var to hold the stats and avoid multiple queries. + * + * @var array + */ + private static $stats = []; + /** * Set the post-type for this stat. * @@ -38,49 +45,62 @@ public function set_post_type( $post_type ) { */ public function get_data( $period = 'week' ) { + if ( ! isset( self::$stats[ $this->post_type ] ) ) { + self::$stats[ $this->post_type ] = []; + } + if ( isset( self::$stats[ $this->post_type ][ $period ] ) ) { + return self::$stats[ $this->post_type ][ $period ]; + } + switch ( $period ) { case 'all': - return (array) \wp_count_posts( $this->post_type ); + self::$stats[ $this->post_type ][ $period ] = (array) \wp_count_posts( $this->post_type ); + return self::$stats[ $this->post_type ][ $period ]; case 'day': - return $this->get_posts_stats_by_date( [ + self::$stats[ $this->post_type ][ $period ] = $this->get_posts_stats_by_date( [ [ 'after' => 'today', 'inclusive' => true, ], ] ); + return self::$stats[ $this->post_type ][ $period ]; case 'week': - return $this->get_posts_stats_by_date( [ + self::$stats[ $this->post_type ][ $period ] = $this->get_posts_stats_by_date( [ [ 'after' => '-1 week', 'inclusive' => true, ], ] ); + return self::$stats[ $this->post_type ][ $period ]; case 'month': - return $this->get_posts_stats_by_date( [ + self::$stats[ $this->post_type ][ $period ] = $this->get_posts_stats_by_date( [ [ 'after' => '-1 month', 'inclusive' => true, ], ] ); + return self::$stats[ $this->post_type ][ $period ]; case 'year': - return $this->get_posts_stats_by_date( [ + self::$stats[ $this->post_type ][ $period ] = $this->get_posts_stats_by_date( [ [ 'after' => '-1 year', 'inclusive' => true, ], ] ); + return self::$stats[ $this->post_type ][ $period ]; default: - return $this->get_posts_stats_by_date( [ + self::$stats[ $this->post_type ][ $period ] = $this->get_posts_stats_by_date( [ [ 'after' => $period, 'inclusive' => true, ], ] ); + return self::$stats[ $this->post_type ][ $period ]; } } From b2e3d2f7def8dbc69141c0419c10570606c6efe8 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 6 Feb 2024 11:51:29 +0200 Subject: [PATCH 016/490] Add words stats to report --- views/admin-page.php | 28 ++++++++++++++++------------ views/stat-posts.php | 41 ++++++++++++++++++++++++++++++----------- 2 files changed, 46 insertions(+), 23 deletions(-) diff --git a/views/admin-page.php b/views/admin-page.php index d1cf2a2b2..d201ac54c 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -38,24 +38,28 @@ esc_html__( 'Day', 'progress-planner' ), - 'period' => 'day', - 'post_type' => $post_type, + 'period' => esc_html__( 'Day', 'progress-planner' ), + 'period' => 'day', + 'post_type' => $post_type, + 'post_type_label' => $post_type_object->label, ], [ - 'label' => esc_html__( 'Week', 'progress-planner' ), - 'period' => 'week', - 'post_type' => $post_type, + 'period' => esc_html__( 'Week', 'progress-planner' ), + 'period' => 'week', + 'post_type' => $post_type, + 'post_type_label' => $post_type_object->label, ], [ - 'label' => esc_html__( 'Month', 'progress-planner' ), - 'period' => 'month', - 'post_type' => $post_type, + 'period' => esc_html__( 'Month', 'progress-planner' ), + 'period' => 'month', + 'post_type' => $post_type, + 'post_type_label' => $post_type_object->label, ], [ - 'label' => esc_html__( 'Year', 'progress-planner' ), - 'period' => 'year', - 'post_type' => $post_type, + 'period' => esc_html__( 'Year', 'progress-planner' ), + 'period' => 'year', + 'post_type' => $post_type, + 'post_type_label' => $post_type_object->label, ], ]; diff --git a/views/stat-posts.php b/views/stat-posts.php index 4fafc70b7..712630803 100644 --- a/views/stat-posts.php +++ b/views/stat-posts.php @@ -4,15 +4,34 @@ * * @package ProgressPlanner */ +?> -printf( - '

%s: %s

', - esc_html( $line['label'] ), - esc_html( - \ProgressPlanner\Progress_Planner::get_instance() - ->get_stats() - ->get_stat( 'posts' ) - ->set_post_type( $line['post_type'] ) - ->get_data( $line['period'] )['count'] - ) -); +

+ +

+

+ get_stats() + ->get_stat( 'posts' ) + ->set_post_type( $line['post_type'] ) + ->get_data( $line['period'] )['count'] + ), + esc_html( + \ProgressPlanner\Progress_Planner::get_instance() + ->get_stats() + ->get_stat( 'posts' ) + ->set_post_type( $line['post_type'] ) + ->get_data( $line['period'] )['word_count'] + ) + ); + ?> +

From 5844d4f2c8b51c052f5038ea2c8b9deed7b80888 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 6 Feb 2024 12:06:15 +0200 Subject: [PATCH 017/490] improve stats presentation --- views/admin-page.php | 78 +++++++++++++++++++++++++------------------- views/stat-posts.php | 37 --------------------- 2 files changed, 44 insertions(+), 71 deletions(-) delete mode 100644 views/stat-posts.php diff --git a/views/admin-page.php b/views/admin-page.php index d201ac54c..467738e2d 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -5,7 +5,6 @@ * @package ProgressPlanner */ -$progress_planner = \ProgressPlanner\Progress_Planner::get_instance(); ?>
@@ -19,13 +18,56 @@

label ); ?>

+ + + + + + + esc_html__( 'Day', 'progress-planner' ), + 'week' => esc_html__( 'Week', 'progress-planner' ), + 'month' => esc_html__( 'Month', 'progress-planner' ), + 'year' => esc_html__( 'Year', 'progress-planner' ), + ] as $period => $period_label ) : + ?> + + + + + + +
+ + + + + +
+ + + get_stats() + ->get_stat( 'posts' ) + ->set_post_type( $post_type ) + ->get_data( $period )['count']; + ?> + + get_stats() + ->get_stat( 'posts' ) + ->set_post_type( $post_type ) + ->get_data( $period )['word_count']; + ?> +

get_stats() ->get_stat( 'posts' ) ->set_post_type( $post_type ) @@ -35,37 +77,5 @@ ?>

- esc_html__( 'Day', 'progress-planner' ), - 'period' => 'day', - 'post_type' => $post_type, - 'post_type_label' => $post_type_object->label, - ], - [ - 'period' => esc_html__( 'Week', 'progress-planner' ), - 'period' => 'week', - 'post_type' => $post_type, - 'post_type_label' => $post_type_object->label, - ], - [ - 'period' => esc_html__( 'Month', 'progress-planner' ), - 'period' => 'month', - 'post_type' => $post_type, - 'post_type_label' => $post_type_object->label, - ], - [ - 'period' => esc_html__( 'Year', 'progress-planner' ), - 'period' => 'year', - 'post_type' => $post_type, - 'post_type_label' => $post_type_object->label, - ], - ]; - - foreach ( $lines as $line ) { - include PROGRESS_PLANNER_DIR . '/views/stat-posts.php'; - } - ?>
diff --git a/views/stat-posts.php b/views/stat-posts.php deleted file mode 100644 index 712630803..000000000 --- a/views/stat-posts.php +++ /dev/null @@ -1,37 +0,0 @@ - - -

- -

-

- get_stats() - ->get_stat( 'posts' ) - ->set_post_type( $line['post_type'] ) - ->get_data( $line['period'] )['count'] - ), - esc_html( - \ProgressPlanner\Progress_Planner::get_instance() - ->get_stats() - ->get_stat( 'posts' ) - ->set_post_type( $line['post_type'] ) - ->get_data( $line['period'] )['word_count'] - ) - ); - ?> -

From 731b978a17bb27dda5c3241dfb45fdd6300862ca Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 6 Feb 2024 12:20:08 +0200 Subject: [PATCH 018/490] improve readability --- includes/stats/class-stat-posts.php | 68 +++++++++++++---------------- 1 file changed, 30 insertions(+), 38 deletions(-) diff --git a/includes/stats/class-stat-posts.php b/includes/stats/class-stat-posts.php index 215a3e69f..c3950036c 100644 --- a/includes/stats/class-stat-posts.php +++ b/includes/stats/class-stat-posts.php @@ -54,53 +54,40 @@ public function get_data( $period = 'week' ) { switch ( $period ) { case 'all': - self::$stats[ $this->post_type ][ $period ] = (array) \wp_count_posts( $this->post_type ); - return self::$stats[ $this->post_type ][ $period ]; + $stats = (array) \wp_count_posts( $this->post_type ); + + self::$stats[ $this->post_type ][ $period ] = $stats; + return $stats; case 'day': - self::$stats[ $this->post_type ][ $period ] = $this->get_posts_stats_by_date( [ - [ - 'after' => 'today', - 'inclusive' => true, - ], - ] ); - return self::$stats[ $this->post_type ][ $period ]; + $stats = $this->get_posts_stats_by_date( 'today' ); + + self::$stats[ $this->post_type ][ $period ] = $stats; + return $stats; case 'week': - self::$stats[ $this->post_type ][ $period ] = $this->get_posts_stats_by_date( [ - [ - 'after' => '-1 week', - 'inclusive' => true, - ], - ] ); - return self::$stats[ $this->post_type ][ $period ]; + $stats = $this->get_posts_stats_by_date( '-1 week' ); + + self::$stats[ $this->post_type ][ $period ] = $stats; + return $stats; case 'month': - self::$stats[ $this->post_type ][ $period ] = $this->get_posts_stats_by_date( [ - [ - 'after' => '-1 month', - 'inclusive' => true, - ], - ] ); - return self::$stats[ $this->post_type ][ $period ]; + $stats = $this->get_posts_stats_by_date( '-1 month' ); + + self::$stats[ $this->post_type ][ $period ] = $stats; + return $stats; case 'year': - self::$stats[ $this->post_type ][ $period ] = $this->get_posts_stats_by_date( [ - [ - 'after' => '-1 year', - 'inclusive' => true, - ], - ] ); - return self::$stats[ $this->post_type ][ $period ]; + $stats = $this->get_posts_stats_by_date( '-1 year' ); + + self::$stats[ $this->post_type ][ $period ] = $stats; + return $stats; default: - self::$stats[ $this->post_type ][ $period ] = $this->get_posts_stats_by_date( [ - [ - 'after' => $period, - 'inclusive' => true, - ], - ] ); - return self::$stats[ $this->post_type ][ $period ]; + $stats = $this->get_posts_stats_by_date( $period ); + + self::$stats[ $this->post_type ][ $period ] = $stats; + return $stats; } } @@ -115,7 +102,12 @@ private function get_posts_stats_by_date( $date_query ) { 'posts_per_page' => 1000, 'post_type' => $this->post_type, 'post_status' => 'publish', - 'date_query' => $date_query, + 'date_query' => [ + [ + 'after' => $date_query, + 'inclusive' => true, + ], + ], 'suppress_filters' => false, ); From 8ac832397743c2a81005a53835590731b0a7bb75 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 6 Feb 2024 12:29:08 +0200 Subject: [PATCH 019/490] Add stats for 2 weeks & 3 weeks --- views/admin-page.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/views/admin-page.php b/views/admin-page.php index 467738e2d..ec74d73a7 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -32,10 +32,12 @@ esc_html__( 'Day', 'progress-planner' ), - 'week' => esc_html__( 'Week', 'progress-planner' ), - 'month' => esc_html__( 'Month', 'progress-planner' ), - 'year' => esc_html__( 'Year', 'progress-planner' ), + 'day' => esc_html__( 'Day', 'progress-planner' ), + 'week' => esc_html__( 'Week', 'progress-planner' ), + '-2 weeks' => esc_html__( '2 Weeks', 'progress-planner' ), + '-3 weeks' => esc_html__( '3 Weeks', 'progress-planner' ), + 'month' => esc_html__( 'Month', 'progress-planner' ), + 'year' => esc_html__( 'Year', 'progress-planner' ), ] as $period => $period_label ) : ?> From fae39cb6c8c4a0cbb35283ad22d39457a03a71ac Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 6 Feb 2024 12:51:17 +0200 Subject: [PATCH 020/490] Add composer PHPCS linter --- .gitignore | 4 ++++ composer.json | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 .gitignore create mode 100644 composer.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..96fd02697 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ + +vendor/ + +composer.lock diff --git a/composer.json b/composer.json new file mode 100644 index 000000000..d3de0ff35 --- /dev/null +++ b/composer.json @@ -0,0 +1,40 @@ +{ + "name": "emilia-capital/progress-planner", + "description": "The Progress Planner WordPress plugin.", + "type": "wordpress-plugin", + "license": "GPL-3.0-or-later", + "authors": [ + { + "name": "Joost de Valk", + "email": "joost@joost.blog" + } + ], + "require-dev": { + "wp-coding-standards/wpcs": "^3.0", + "phpcompatibility/phpcompatibility-wp": "*", + "php-parallel-lint/php-parallel-lint": "^1.3", + "yoast/wp-test-utils": "^1.2" + }, + "scripts": { + "check-cs": [ + "@php ./vendor/bin/phpcs" + ], + "fix-cs": [ + "@php ./vendor/bin/phpcbf" + ], + "lint": [ + "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --show-deprecated --exclude vendor --exclude node_modules --exclude .git" + ], + "lint-blueprint": [ + "@php -r \"exit( intval( is_null( json_decode( file_get_contents( './.wordpress-org/blueprints/blueprint.json' ) ) ) ) );\"" + ], + "test": [ + "@php ./vendor/phpunit/phpunit/phpunit" + ] + }, + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } + } +} From 29859535a84ba90c633c073fb2efd2efb49700b3 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 6 Feb 2024 12:51:50 +0200 Subject: [PATCH 021/490] CS fixes --- includes/admin/class-page.php | 2 ++ includes/class-admin.php | 2 ++ includes/class-stats.php | 2 +- includes/stats/class-stat-posts.php | 18 +++++++++-------- includes/stats/class-stat-terms.php | 8 ++++++-- includes/stats/class-stat.php | 2 ++ progress-planner.php | 2 ++ views/admin-page.php | 31 ++++++++++++++++------------- 8 files changed, 42 insertions(+), 25 deletions(-) diff --git a/includes/admin/class-page.php b/includes/admin/class-page.php index 8a10a6846..c624aea82 100644 --- a/includes/admin/class-page.php +++ b/includes/admin/class-page.php @@ -1,6 +1,8 @@ 1000, - 'post_type' => $this->post_type, - 'post_status' => 'publish', - 'date_query' => [ + $args = [ + 'posts_per_page' => 1000, // phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page + 'post_type' => $this->post_type, + 'post_status' => 'publish', + 'date_query' => [ [ 'after' => $date_query, 'inclusive' => true, ], ], 'suppress_filters' => false, - ); + ]; $posts = get_posts( $args ); @@ -119,10 +121,10 @@ private function get_posts_stats_by_date( $date_query ) { $word_count += str_word_count( $post->post_content ); } - return array( + return [ 'count' => count( $posts ), 'post_ids' => \wp_list_pluck( $posts, 'ID' ), 'word_count' => $word_count, - ); + ]; } } diff --git a/includes/stats/class-stat-terms.php b/includes/stats/class-stat-terms.php index ecca6e77e..d14396553 100644 --- a/includes/stats/class-stat-terms.php +++ b/includes/stats/class-stat-terms.php @@ -1,6 +1,8 @@ (array) \wp_count_terms( [ 'taxonomy' => $this->taxonomy ] ), - ); + ]; } } diff --git a/includes/stats/class-stat.php b/includes/stats/class-stat.php index 4a2b670ed..d2ff72177 100644 --- a/includes/stats/class-stat.php +++ b/includes/stats/class-stat.php @@ -3,6 +3,8 @@ * An object containing info about an individual stat. * * This is an abstract class, meant to be extended by individual stat classes. + * + * @package ProgressPlanner */ namespace ProgressPlanner\Stats; diff --git a/progress-planner.php b/progress-planner.php index 578cb1961..cd32120b8 100644 --- a/progress-planner.php +++ b/progress-planner.php @@ -1,6 +1,8 @@ - - $post_type_object ) : ?> - public ) : ?> + + $progress_planner_post_type_object ) : ?> + public ) : ?> -

label ); ?>

+

label ); ?>

@@ -67,12 +69,13 @@

get_stats() ->get_stat( 'posts' ) - ->set_post_type( $post_type ) + ->set_post_type( $progress_planner_post_type ) ->get_data( 'all' )['publish'] ) ); From 8d0b1ace32ad643d788cf53753ba5621d0387f2d Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 6 Feb 2024 14:06:56 +0200 Subject: [PATCH 022/490] Revert "improve readability" This reverts commit 731b978a17bb27dda5c3241dfb45fdd6300862ca. --- includes/stats/class-stat-posts.php | 78 ++++++++++++++++++----------- 1 file changed, 48 insertions(+), 30 deletions(-) diff --git a/includes/stats/class-stat-posts.php b/includes/stats/class-stat-posts.php index 619181b22..837734467 100644 --- a/includes/stats/class-stat-posts.php +++ b/includes/stats/class-stat-posts.php @@ -56,40 +56,63 @@ public function get_data( $period = 'week' ) { switch ( $period ) { case 'all': - $stats = (array) \wp_count_posts( $this->post_type ); - - self::$stats[ $this->post_type ][ $period ] = $stats; - return $stats; + self::$stats[ $this->post_type ][ $period ] = (array) \wp_count_posts( $this->post_type ); + return self::$stats[ $this->post_type ][ $period ]; case 'day': - $stats = $this->get_posts_stats_by_date( 'today' ); - - self::$stats[ $this->post_type ][ $period ] = $stats; - return $stats; + self::$stats[ $this->post_type ][ $period ] = $this->get_posts_stats_by_date( + [ + [ + 'after' => 'today', + 'inclusive' => true, + ], + ] + ); + return self::$stats[ $this->post_type ][ $period ]; case 'week': - $stats = $this->get_posts_stats_by_date( '-1 week' ); - - self::$stats[ $this->post_type ][ $period ] = $stats; - return $stats; + self::$stats[ $this->post_type ][ $period ] = $this->get_posts_stats_by_date( + [ + [ + 'after' => '-1 week', + 'inclusive' => true, + ], + ] + ); + return self::$stats[ $this->post_type ][ $period ]; case 'month': - $stats = $this->get_posts_stats_by_date( '-1 month' ); - - self::$stats[ $this->post_type ][ $period ] = $stats; - return $stats; + self::$stats[ $this->post_type ][ $period ] = $this->get_posts_stats_by_date( + [ + [ + 'after' => '-1 month', + 'inclusive' => true, + ], + ] + ); + return self::$stats[ $this->post_type ][ $period ]; case 'year': - $stats = $this->get_posts_stats_by_date( '-1 year' ); - - self::$stats[ $this->post_type ][ $period ] = $stats; - return $stats; + self::$stats[ $this->post_type ][ $period ] = $this->get_posts_stats_by_date( + [ + [ + 'after' => '-1 year', + 'inclusive' => true, + ], + ] + ); + return self::$stats[ $this->post_type ][ $period ]; default: - $stats = $this->get_posts_stats_by_date( $period ); - - self::$stats[ $this->post_type ][ $period ] = $stats; - return $stats; + self::$stats[ $this->post_type ][ $period ] = $this->get_posts_stats_by_date( + [ + [ + 'after' => $period, + 'inclusive' => true, + ], + ] + ); + return self::$stats[ $this->post_type ][ $period ]; } } @@ -104,12 +127,7 @@ private function get_posts_stats_by_date( $date_query ) { 'posts_per_page' => 1000, // phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page 'post_type' => $this->post_type, 'post_status' => 'publish', - 'date_query' => [ - [ - 'after' => $date_query, - 'inclusive' => true, - ], - ], + 'date_query' => $date_query, 'suppress_filters' => false, ]; From db46accb2ab17876f2d92799e96a44bba31e1d34 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 6 Feb 2024 14:58:29 +0200 Subject: [PATCH 023/490] Add basic Settings class --- includes/class-progress-planner.php | 21 ++++++- includes/class-settings.php | 91 +++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 includes/class-settings.php diff --git a/includes/class-progress-planner.php b/includes/class-progress-planner.php index 2115b14e3..e5e7a49cf 100644 --- a/includes/class-progress-planner.php +++ b/includes/class-progress-planner.php @@ -33,6 +33,13 @@ class Progress_Planner { */ private $admin; + /** + * The Settings object. + * + * @var \ProgressPlanner\Settings + */ + private $settings; + /** * Get the single instance of this class. * @@ -50,8 +57,18 @@ public static function get_instance() { * Constructor. */ private function __construct() { - $this->admin = new Admin(); - $this->stats = new Stats(); + $this->admin = new Admin(); + $this->settings = new Settings(); + $this->stats = new Stats(); + } + + /** + * Get the settings object. + * + * @return \ProgressPlanner\Settings + */ + public function get_settings() { + return $this->settings; } /** diff --git a/includes/class-settings.php b/includes/class-settings.php new file mode 100644 index 000000000..5f270dcd4 --- /dev/null +++ b/includes/class-settings.php @@ -0,0 +1,91 @@ +option_name, [] ); + + // Get the value for current week & month. + $current_value = $this->get_current_value(); + + // Merge the saved value with the default value. + return \array_replace_recursive( $current_value, $saved_value ); + } + + /** + * Get the value for the current week & month. + * + * @return array + */ + private function get_current_value() { + // Get the values for current week and month. + $curr_y = \gmdate( 'Y' ); + $curr_m = \gmdate( 'n' ); + $curr_w = \gmdate( 'W' ); + $curr_value = [ + 'stats' => [ + $curr_y => [ + 'weeks' => [ + $curr_w => [ + 'posts' => [], + 'words' => [], + ], + ], + 'months' => [ + $curr_m => [ + 'posts' => [], + 'words' => [], + ], + ], + ], + ], + ]; + foreach ( \array_keys( \get_post_types( [ 'public' => true ] ) ) as $post_type ) { + $week_stats = Progress_Planner::get_instance() + ->get_stats() + ->get_stat( 'posts' ) + ->set_post_type( $post_type ) + ->get_data( 'this week' ); + + $month_stats = Progress_Planner::get_instance() + ->get_stats() + ->get_stat( 'posts' ) + ->set_post_type( $post_type ) + ->get_data( gmdate( 'F Y' ) ); + + $curr_value['stats'][ $curr_y ]['weeks'][ $curr_w ]['posts'][ $post_type ] = $week_stats['count']; + $curr_value['stats'][ $curr_y ]['weeks'][ $curr_w ]['words'][ $post_type ] = $week_stats['word_count']; + $curr_value['stats'][ $curr_y ]['months'][ $curr_m ]['posts'][ $post_type ] = $month_stats['count']; + $curr_value['stats'][ $curr_y ]['months'][ $curr_m ]['words'][ $post_type ] = $month_stats['word_count']; + } + + return $curr_value; + } + + /** + * Update value for previous week. + */ +} From 65819e685e2910593bc82e792d64496ad56c31e5 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 6 Feb 2024 14:58:59 +0200 Subject: [PATCH 024/490] Add method to update setting for previous months/weeks --- includes/class-settings.php | 43 ++++++++++++++++++++++++++++- includes/stats/class-stat-posts.php | 2 +- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/includes/class-settings.php b/includes/class-settings.php index 5f270dcd4..37585c633 100644 --- a/includes/class-settings.php +++ b/includes/class-settings.php @@ -86,6 +86,47 @@ private function get_current_value() { } /** - * Update value for previous week. + * Update value for a previous, unsaved week. + * + * @param string $interval_type The interval type. Can be "week" or "month". + * @param int $interval_value The number of weeks or months back to update the value for. + * + * @return bool Returns the result of the update_option function. */ + public function update_value_previous_unsaved_week( $interval_type = 'weeks', $interval_value = 0 ) { + // Get the saved value. + $saved_value = \get_option( $this->option_name, [] ); + + // Get the year & week numbers for the defined week/month. + $year = \gmdate( 'Y', strtotime( "-$interval_value $interval_type" ) ); + $interval_type_nr = \gmdate( + 'weeks' === $interval_type ? 'W' : 'n', + strtotime( "-$interval_value $interval_type" ) + ); + + foreach ( \array_keys( \get_post_types( [ 'public' => true ] ) ) as $post_type ) { + $interval_stats = Progress_Planner::get_instance() + ->get_stats() + ->get_stat( 'posts' ) + ->set_post_type( $post_type ) + ->get_posts_stats_by_date( + [ + [ + 'after' => '-' . ( $interval_value + 1 ) . $interval_type, + 'inclusive' => true, + ], + [ + 'before' => '-' . $interval_value . $interval_type, + 'inclusive' => false, + ], + ] + ); + + // Set the value. + $saved_values['stats'][ $year ][ $interval_type ][ $interval_type_nr ]['posts'][ $post_type ] = $interval_stats['count']; + } + + // Update the option value. + return \update_option( $this->option_name, $saved_value ); + } } diff --git a/includes/stats/class-stat-posts.php b/includes/stats/class-stat-posts.php index 837734467..fd858adfc 100644 --- a/includes/stats/class-stat-posts.php +++ b/includes/stats/class-stat-posts.php @@ -122,7 +122,7 @@ public function get_data( $period = 'week' ) { * @param array $date_query The date query. * @return array */ - private function get_posts_stats_by_date( $date_query ) { + public function get_posts_stats_by_date( $date_query ) { $args = [ 'posts_per_page' => 1000, // phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page 'post_type' => $this->post_type, From a3b1ab4c620b19d6a4616fe9deb15111466c33ba Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 6 Feb 2024 15:07:43 +0200 Subject: [PATCH 025/490] Update method name --- includes/class-settings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-settings.php b/includes/class-settings.php index 37585c633..77a7abea1 100644 --- a/includes/class-settings.php +++ b/includes/class-settings.php @@ -93,7 +93,7 @@ private function get_current_value() { * * @return bool Returns the result of the update_option function. */ - public function update_value_previous_unsaved_week( $interval_type = 'weeks', $interval_value = 0 ) { + public function update_value_previous_unsaved_interval( $interval_type = 'weeks', $interval_value = 0 ) { // Get the saved value. $saved_value = \get_option( $this->option_name, [] ); From 1f2cedc9e323a9bc4865453d1dbe7700a407220e Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 7 Feb 2024 11:33:58 +0200 Subject: [PATCH 026/490] refactor some structure --- includes/class-settings.php | 104 +++++++++++++++++--------- includes/stats/class-stat-posts.php | 85 +-------------------- includes/stats/class-stat-terms.php | 4 +- includes/stats/class-stat.php | 25 ++++++- phpcs.xml.dist | 1 + views/admin-page.php | 110 ++++++++++++++-------------- 6 files changed, 152 insertions(+), 177 deletions(-) diff --git a/includes/class-settings.php b/includes/class-settings.php index 77a7abea1..8289899b8 100644 --- a/includes/class-settings.php +++ b/includes/class-settings.php @@ -22,9 +22,15 @@ class Settings { /** * Get the option value. * + * @param string[] ...$args Get the value for a specific key in the array. + * This will go over the array recursively, returning the value for the last key. + * Example: If the value is ['a' => ['b' => 'c']], get_value('a', 'b') will return 'c'. + * If the key does not exist, it will return null. + * If no keys are provided, it will return the entire array. + * * @return array */ - public function get_value() { + public function get_value( ...$args ) { // Get the saved value. $saved_value = \get_option( $this->option_name, [] ); @@ -32,7 +38,17 @@ public function get_value() { $current_value = $this->get_current_value(); // Merge the saved value with the default value. - return \array_replace_recursive( $current_value, $saved_value ); + $value = \array_replace_recursive( $current_value, $saved_value ); + + // Get the value for a specific key. + foreach ( $args as $arg ) { + if ( ! isset( $value[ $arg ] ) ) { + $value = null; + break; + } + $value = $value[ $arg ]; + } + return $value; } /** @@ -42,9 +58,9 @@ public function get_value() { */ private function get_current_value() { // Get the values for current week and month. - $curr_y = \gmdate( 'Y' ); - $curr_m = \gmdate( 'n' ); - $curr_w = \gmdate( 'W' ); + $curr_y = (int) \gmdate( 'Y' ); + $curr_m = (int) \gmdate( 'n' ); + $curr_w = (int) \gmdate( 'W' ); $curr_value = [ 'stats' => [ $curr_y => [ @@ -63,18 +79,31 @@ private function get_current_value() { ], ], ]; + + $stats = Progress_Planner::get_instance()->get_stats()->get_stat( 'posts' ); foreach ( \array_keys( \get_post_types( [ 'public' => true ] ) ) as $post_type ) { - $week_stats = Progress_Planner::get_instance() - ->get_stats() - ->get_stat( 'posts' ) - ->set_post_type( $post_type ) - ->get_data( 'this week' ); - - $month_stats = Progress_Planner::get_instance() - ->get_stats() - ->get_stat( 'posts' ) - ->set_post_type( $post_type ) - ->get_data( gmdate( 'F Y' ) ); + // Set the post-type. + $stats->set_post_type( $post_type ); + + // Get weekly stats. + $week_stats = $stats->set_date_query( + [ + [ + 'after' => '-1 week', + 'inclusive' => true, + ], + ] + )->get_data(); + + // Get monthly stats. + $month_stats = $stats->set_date_query( + [ + [ + 'after' => gmdate( 'F Y' ), + 'inclusive' => true, + ], + ] + )->get_data(); $curr_value['stats'][ $curr_y ]['weeks'][ $curr_w ]['posts'][ $post_type ] = $week_stats['count']; $curr_value['stats'][ $curr_y ]['weeks'][ $curr_w ]['words'][ $post_type ] = $week_stats['word_count']; @@ -95,35 +124,40 @@ private function get_current_value() { */ public function update_value_previous_unsaved_interval( $interval_type = 'weeks', $interval_value = 0 ) { // Get the saved value. - $saved_value = \get_option( $this->option_name, [] ); + $saved_value = $this->get_value(); // Get the year & week numbers for the defined week/month. - $year = \gmdate( 'Y', strtotime( "-$interval_value $interval_type" ) ); - $interval_type_nr = \gmdate( + $year = (int) \gmdate( 'Y', strtotime( "-$interval_value $interval_type" ) ); + $interval_type_nr = (int) \gmdate( 'weeks' === $interval_type ? 'W' : 'n', strtotime( "-$interval_value $interval_type" ) ); + $stats = Progress_Planner::get_instance()->get_stats()->get_stat( 'posts' ); foreach ( \array_keys( \get_post_types( [ 'public' => true ] ) ) as $post_type ) { - $interval_stats = Progress_Planner::get_instance() - ->get_stats() - ->get_stat( 'posts' ) - ->set_post_type( $post_type ) - ->get_posts_stats_by_date( + if ( + isset( $saved_value['stats'][ $year ][ $interval_type ][ $interval_type_nr ]['posts'][ $post_type ] ) && + isset( $saved_value['stats'][ $year ][ $interval_type ][ $interval_type_nr ]['words'][ $post_type ] ) + ) { + continue; + } + + $interval_stats = $stats->set_post_type( $post_type )->set_date_query( + [ [ - [ - 'after' => '-' . ( $interval_value + 1 ) . $interval_type, - 'inclusive' => true, - ], - [ - 'before' => '-' . $interval_value . $interval_type, - 'inclusive' => false, - ], - ] - ); + 'after' => '-' . ( $interval_value + 1 ) . ' ' . $interval_type, + 'inclusive' => true, + ], + [ + 'before' => '-' . $interval_value . ' ' . $interval_type, + 'inclusive' => false, + ], + ] + )->get_data(); // Set the value. - $saved_values['stats'][ $year ][ $interval_type ][ $interval_type_nr ]['posts'][ $post_type ] = $interval_stats['count']; + $saved_value['stats'][ $year ][ $interval_type ][ $interval_type_nr ]['posts'][ $post_type ] = $interval_stats['count']; + $saved_value['stats'][ $year ][ $interval_type ][ $interval_type_nr ]['words'][ $post_type ] = $interval_stats['word_count']; } // Update the option value. diff --git a/includes/stats/class-stat-posts.php b/includes/stats/class-stat-posts.php index fd858adfc..d02b1de29 100644 --- a/includes/stats/class-stat-posts.php +++ b/includes/stats/class-stat-posts.php @@ -39,95 +39,16 @@ public function set_post_type( $post_type ) { } /** - * Get the stat data. + * Get the data. * - * @param string $period The period to get the data for. - * - * @return array - */ - public function get_data( $period = 'week' ) { - - if ( ! isset( self::$stats[ $this->post_type ] ) ) { - self::$stats[ $this->post_type ] = []; - } - if ( isset( self::$stats[ $this->post_type ][ $period ] ) ) { - return self::$stats[ $this->post_type ][ $period ]; - } - - switch ( $period ) { - case 'all': - self::$stats[ $this->post_type ][ $period ] = (array) \wp_count_posts( $this->post_type ); - return self::$stats[ $this->post_type ][ $period ]; - - case 'day': - self::$stats[ $this->post_type ][ $period ] = $this->get_posts_stats_by_date( - [ - [ - 'after' => 'today', - 'inclusive' => true, - ], - ] - ); - return self::$stats[ $this->post_type ][ $period ]; - - case 'week': - self::$stats[ $this->post_type ][ $period ] = $this->get_posts_stats_by_date( - [ - [ - 'after' => '-1 week', - 'inclusive' => true, - ], - ] - ); - return self::$stats[ $this->post_type ][ $period ]; - - case 'month': - self::$stats[ $this->post_type ][ $period ] = $this->get_posts_stats_by_date( - [ - [ - 'after' => '-1 month', - 'inclusive' => true, - ], - ] - ); - return self::$stats[ $this->post_type ][ $period ]; - - case 'year': - self::$stats[ $this->post_type ][ $period ] = $this->get_posts_stats_by_date( - [ - [ - 'after' => '-1 year', - 'inclusive' => true, - ], - ] - ); - return self::$stats[ $this->post_type ][ $period ]; - - default: - self::$stats[ $this->post_type ][ $period ] = $this->get_posts_stats_by_date( - [ - [ - 'after' => $period, - 'inclusive' => true, - ], - ] - ); - return self::$stats[ $this->post_type ][ $period ]; - } - } - - /** - * Get posts by dates. - * - * @param array $date_query The date query. * @return array */ - public function get_posts_stats_by_date( $date_query ) { + public function get_data() { $args = [ 'posts_per_page' => 1000, // phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page 'post_type' => $this->post_type, 'post_status' => 'publish', - 'date_query' => $date_query, + 'date_query' => $this->date_query, 'suppress_filters' => false, ]; diff --git a/includes/stats/class-stat-terms.php b/includes/stats/class-stat-terms.php index d14396553..9eca97630 100644 --- a/includes/stats/class-stat-terms.php +++ b/includes/stats/class-stat-terms.php @@ -31,11 +31,9 @@ public function set_taxonomy( $taxonomy ) { /** * Get the stat data. * - * @param string $period The period to get the data for. - * * @return array */ - public function get_data( $period = 'week' ) { + public function get_data() { return [ 'total' => (array) \wp_count_terms( [ 'taxonomy' => $this->taxonomy ] ), ]; diff --git a/includes/stats/class-stat.php b/includes/stats/class-stat.php index d2ff72177..4377cd3da 100644 --- a/includes/stats/class-stat.php +++ b/includes/stats/class-stat.php @@ -17,11 +17,30 @@ abstract class Stat { /** - * Get the stat data. + * Date Query. + * + * The date query, which will be then passed-on to the WP_Date_Query object. + * + * @var array + */ + protected $date_query = []; + + /** + * Set the date query. * - * @param string $period The period to get the data for. + * @param array $date_query The date query. + * + * @return Stat Returns this object to allow chaining methods. + */ + public function set_date_query( $date_query ) { + $this->date_query = $date_query; + return $this; + } + + /** + * Get the stat data. * * @return array */ - abstract public function get_data( $period = 'week' ); + abstract public function get_data(); } diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 9ca2d44fb..13839c80c 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -110,6 +110,7 @@ + diff --git a/views/admin-page.php b/views/admin-page.php index 38b5a34cd..25f5b7501 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -5,6 +5,17 @@ * @package ProgressPlanner */ +// TODO: This pre-populates the option with previous weeks and months values. +// This should be moved to a separate function that can be called from the admin page. +foreach ( [ 1, 2, 3, 4, 5 ] as $prpl_i ) { + \ProgressPlanner\Progress_Planner::get_instance() + ->get_settings() + ->update_value_previous_unsaved_interval( 'weeks', $prpl_i ); + \ProgressPlanner\Progress_Planner::get_instance() + ->get_settings() + ->update_value_previous_unsaved_interval( 'months', $prpl_i ); +} + ?>

@@ -12,12 +23,12 @@

- - $progress_planner_post_type_object ) : ?> - public ) : ?> + + $prpl_post_type_object ) : ?> + public ) : ?> -

label ); ?>

+

label ); ?>

@@ -38,26 +38,28 @@ '-3 weeks' => esc_html__( '3 Weeks', 'progress-planner' ), 'month' => esc_html__( 'Month', 'progress-planner' ), 'year' => esc_html__( 'Year', 'progress-planner' ), - ] as $period => $period_label ) : - ?> + ] as $progress_planner_period => $progress_planner_period_label ) : + ?>
- + - get_stats() ->get_stat( 'posts' ) - ->set_post_type( $post_type ) - ->get_data( $period )['count']; + ->set_post_type( $progress_planner_post_type ) + ->get_data( $progress_planner_period )['count']; ?> - get_stats() ->get_stat( 'posts' ) - ->set_post_type( $post_type ) - ->get_data( $period )['word_count']; + ->set_post_type( $progress_planner_post_type ) + ->get_data( $progress_planner_period )['word_count']; ?>
- esc_html__( 'Day', 'progress-planner' ), - 'week' => esc_html__( 'Week', 'progress-planner' ), - '-2 weeks' => esc_html__( '2 Weeks', 'progress-planner' ), - '-3 weeks' => esc_html__( '3 Weeks', 'progress-planner' ), - 'month' => esc_html__( 'Month', 'progress-planner' ), - 'year' => esc_html__( 'Year', 'progress-planner' ), - ] as $progress_planner_period => $progress_planner_period_label ) : - ?> - - - - - + + + + + + + + +
@@ -30,57 +41,48 @@
- - - get_stats() - ->get_stat( 'posts' ) - ->set_post_type( $progress_planner_post_type ) - ->get_data( $progress_planner_period )['count']; - ?> - - get_stats() - ->get_stat( 'posts' ) - ->set_post_type( $progress_planner_post_type ) - ->get_data( $progress_planner_period )['word_count']; - ?> -
+ get_settings()->get_value( + 'stats', + (int) gmdate( + 'Y', + strtotime( '-' . $prpl_interval_value . ' ' . $prpl_interval_type ) + ), + $prpl_interval_type, + (int) gmdate( + ( 'weeks' === $prpl_interval_type ) ? 'W' : 'n', + strtotime( '-' . $prpl_interval_value . ' ' . $prpl_interval_type ) + ), + 'posts', + $prpl_post_type + ) + ); + ?> + + get_settings()->get_value( + 'stats', + gmdate( 'Y', strtotime( '-' . $prpl_interval_value . ' ' . $prpl_interval_type ) ), + $prpl_interval_type, + gmdate( 'n', strtotime( '-' . $prpl_interval_value . ' ' . $prpl_interval_type ) ), + 'words', + $prpl_post_type + ) + ); + ?> +

- -

- get_stats() - ->get_stat( 'posts' ) - ->set_post_type( $progress_planner_post_type ) - ->get_data( 'all' )['publish'] - ) - ); - ?> -

- From dbd1a6f3f84a9eb6cf162cb99c15cd28afb18deb Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 7 Feb 2024 12:05:28 +0200 Subject: [PATCH 027/490] Add set_value method and refactor get_value --- includes/class-settings.php | 58 +++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/includes/class-settings.php b/includes/class-settings.php index 8289899b8..47a263b25 100644 --- a/includes/class-settings.php +++ b/includes/class-settings.php @@ -40,15 +40,30 @@ public function get_value( ...$args ) { // Merge the saved value with the default value. $value = \array_replace_recursive( $current_value, $saved_value ); - // Get the value for a specific key. - foreach ( $args as $arg ) { - if ( ! isset( $value[ $arg ] ) ) { - $value = null; - break; - } - $value = $value[ $arg ]; - } - return $value; + return empty( $args ) + ? $value + : \_wp_array_get( $value, $args ); + } + + /** + * Update the option value. + * + * @param string[] $args The keys to update. + * This will go over the array recursively, updating the value for the last key. + * See get_value for more info. + * @param mixed $value The new value. + * + * @return bool Returns the result of the update_option function. + */ + public function set_value( $args, $value ) { + // Get the saved value. + $saved_value = \get_option( $this->option_name, [] ); + + // Update item in the array. + \_wp_array_set( $saved_value, $args, $value ); + + // Update the option value. + return \update_option( $this->option_name, $saved_value ); } /** @@ -120,11 +135,9 @@ private function get_current_value() { * @param string $interval_type The interval type. Can be "week" or "month". * @param int $interval_value The number of weeks or months back to update the value for. * - * @return bool Returns the result of the update_option function. + * @return void */ public function update_value_previous_unsaved_interval( $interval_type = 'weeks', $interval_value = 0 ) { - // Get the saved value. - $saved_value = $this->get_value(); // Get the year & week numbers for the defined week/month. $year = (int) \gmdate( 'Y', strtotime( "-$interval_value $interval_type" ) ); @@ -135,13 +148,6 @@ public function update_value_previous_unsaved_interval( $interval_type = 'weeks' $stats = Progress_Planner::get_instance()->get_stats()->get_stat( 'posts' ); foreach ( \array_keys( \get_post_types( [ 'public' => true ] ) ) as $post_type ) { - if ( - isset( $saved_value['stats'][ $year ][ $interval_type ][ $interval_type_nr ]['posts'][ $post_type ] ) && - isset( $saved_value['stats'][ $year ][ $interval_type ][ $interval_type_nr ]['words'][ $post_type ] ) - ) { - continue; - } - $interval_stats = $stats->set_post_type( $post_type )->set_date_query( [ [ @@ -155,12 +161,14 @@ public function update_value_previous_unsaved_interval( $interval_type = 'weeks' ] )->get_data(); - // Set the value. - $saved_value['stats'][ $year ][ $interval_type ][ $interval_type_nr ]['posts'][ $post_type ] = $interval_stats['count']; - $saved_value['stats'][ $year ][ $interval_type ][ $interval_type_nr ]['words'][ $post_type ] = $interval_stats['word_count']; + $this->set_value( + [ 'stats', $year, $interval_type, $interval_type_nr, 'posts', $post_type ], + $interval_stats['count'] + ); + $this->set_value( + [ 'stats', $year, $interval_type, $interval_type_nr, 'words', $post_type ], + $interval_stats['word_count'] + ); } - - // Update the option value. - return \update_option( $this->option_name, $saved_value ); } } From 9566b098e14299e7ef2c5b8b9a9c86a2f5cac157 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 8 Feb 2024 12:29:28 +0200 Subject: [PATCH 028/490] Cleanup --- includes/class-settings.php | 32 ++++++++--------------------- includes/stats/class-stat-posts.php | 7 ------- 2 files changed, 9 insertions(+), 30 deletions(-) diff --git a/includes/class-settings.php b/includes/class-settings.php index 47a263b25..ff7f08f2d 100644 --- a/includes/class-settings.php +++ b/includes/class-settings.php @@ -76,26 +76,9 @@ private function get_current_value() { $curr_y = (int) \gmdate( 'Y' ); $curr_m = (int) \gmdate( 'n' ); $curr_w = (int) \gmdate( 'W' ); - $curr_value = [ - 'stats' => [ - $curr_y => [ - 'weeks' => [ - $curr_w => [ - 'posts' => [], - 'words' => [], - ], - ], - 'months' => [ - $curr_m => [ - 'posts' => [], - 'words' => [], - ], - ], - ], - ], - ]; + $curr_value = []; + $stats = Progress_Planner::get_instance()->get_stats()->get_stat( 'posts' ); - $stats = Progress_Planner::get_instance()->get_stats()->get_stat( 'posts' ); foreach ( \array_keys( \get_post_types( [ 'public' => true ] ) ) as $post_type ) { // Set the post-type. $stats->set_post_type( $post_type ); @@ -110,6 +93,10 @@ private function get_current_value() { ] )->get_data(); + // Set weekly stats. + \_wp_array_set( $curr_value, [ 'stats', $curr_y, 'weeks', $curr_w, 'posts', $post_type ], $week_stats['count'] ); + \_wp_array_set( $curr_value, [ 'stats', $curr_y, 'weeks', $curr_w, 'words', $post_type ], $week_stats['word_count'] ); + // Get monthly stats. $month_stats = $stats->set_date_query( [ @@ -120,10 +107,9 @@ private function get_current_value() { ] )->get_data(); - $curr_value['stats'][ $curr_y ]['weeks'][ $curr_w ]['posts'][ $post_type ] = $week_stats['count']; - $curr_value['stats'][ $curr_y ]['weeks'][ $curr_w ]['words'][ $post_type ] = $week_stats['word_count']; - $curr_value['stats'][ $curr_y ]['months'][ $curr_m ]['posts'][ $post_type ] = $month_stats['count']; - $curr_value['stats'][ $curr_y ]['months'][ $curr_m ]['words'][ $post_type ] = $month_stats['word_count']; + // Set monthly stats. + \_wp_array_set( $curr_value, [ 'stats', $curr_y, 'months', $curr_m, 'posts', $post_type ], $month_stats['count'] ); + \_wp_array_set( $curr_value, [ 'stats', $curr_y, 'months', $curr_m, 'words', $post_type ], $month_stats['word_count'] ); } return $curr_value; diff --git a/includes/stats/class-stat-posts.php b/includes/stats/class-stat-posts.php index d02b1de29..1d90f619d 100644 --- a/includes/stats/class-stat-posts.php +++ b/includes/stats/class-stat-posts.php @@ -19,13 +19,6 @@ class Stat_Posts extends Stat { */ protected $post_type = 'post'; - /** - * Static var to hold the stats and avoid multiple queries. - * - * @var array - */ - private static $stats = []; - /** * Set the post-type for this stat. * From 254a94bfe76e1d8728aa7e069021ac759747951b Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 8 Feb 2024 13:44:27 +0200 Subject: [PATCH 029/490] POC - Experiment with Chart --- includes/admin/class-chart.php | 59 +++++++++++ includes/class-admin.php | 19 ++++ includes/class-progress-planner.php | 9 ++ includes/class-settings.php | 46 +++++++-- views/admin-page.php | 146 +++++++++++++++++----------- 5 files changed, 216 insertions(+), 63 deletions(-) create mode 100644 includes/admin/class-chart.php diff --git a/includes/admin/class-chart.php b/includes/admin/class-chart.php new file mode 100644 index 000000000..8041d237e --- /dev/null +++ b/includes/admin/class-chart.php @@ -0,0 +1,59 @@ +register_hooks(); + } + + /** + * Register the hooks. + */ + private function register_hooks() { + \add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); + } + + /** + * Enqueue the scripts and styles. + */ + public function enqueue_scripts() { + \wp_enqueue_script( 'chartjs', 'https://cdn.jsdelivr.net/npm/chart.js', [], '4.4.1', true ); + } + + /** + * Render the chart. + * + * @param string $id The ID of the chart. + * @param string $type The type of chart. + * @param array $data The data for the chart. + * @param array $options The options for the chart. + * + * @return void + */ + public function render_chart( $id, $type, $data, $options ) { + $id = 'progress-planner-chart-' . $id; + ?> + + + admin_page = new Admin\Page(); + $this->chart = new Admin\Chart(); + } + + /** + * Get the admin page object. + * + * @return \ProgressPlanner\Admin\Page + */ + public function get_admin_page() { + return $this->admin_page; + } + + /** + * Get the chart object. + * + * @return \ProgressPlanner\Admin\Chart + */ + public function get_chart() { + return $this->chart; } } diff --git a/includes/class-progress-planner.php b/includes/class-progress-planner.php index e5e7a49cf..e6c2a3492 100644 --- a/includes/class-progress-planner.php +++ b/includes/class-progress-planner.php @@ -79,4 +79,13 @@ public function get_settings() { public function get_stats() { return $this->stats; } + + /** + * Get the admin object. + * + * @return \ProgressPlanner\Admin + */ + public function get_admin() { + return $this->admin; + } } diff --git a/includes/class-settings.php b/includes/class-settings.php index ff7f08f2d..f813fea08 100644 --- a/includes/class-settings.php +++ b/includes/class-settings.php @@ -22,15 +22,17 @@ class Settings { /** * Get the option value. * - * @param string[] ...$args Get the value for a specific key in the array. - * This will go over the array recursively, returning the value for the last key. - * Example: If the value is ['a' => ['b' => 'c']], get_value('a', 'b') will return 'c'. - * If the key does not exist, it will return null. - * If no keys are provided, it will return the entire array. + * @param string[] $args Get the value for a specific key in the array. + * This will go over the array recursively, returning the value for the last key. + * Example: If the value is ['a' => ['b' => 'c']], get_value('a', 'b') will return 'c'. + * If the key does not exist, it will return null. + * If no keys are provided, it will return the entire array. + * @param string $order The order. Can be "ASC" or "DESC". + * If null, then the order will be the same as the saved value. * * @return array */ - public function get_value( ...$args ) { + public function get_value( $args, $order = null ) { // Get the saved value. $saved_value = \get_option( $this->option_name, [] ); @@ -40,9 +42,39 @@ public function get_value( ...$args ) { // Merge the saved value with the default value. $value = \array_replace_recursive( $current_value, $saved_value ); - return empty( $args ) + $value = empty( $args ) ? $value : \_wp_array_get( $value, $args ); + + return null === $order + ? $value + : $this->order( $value, $order ); + } + + /** + * Get the value, ordered by date. + * + * @param mixed $value The value. + * @param string $order The order. Can be "ASC" or "DESC". + * + * @return array + */ + public function order( $value, $order = 'ASC' ) { + if ( ! is_array( $value ) ) { + return $value; + } + + // Order the array. + if ( 'ASC' === $order ) { + \ksort( $value ); + } else { + \krsort( $value ); + } + + foreach ( $value as $key => $val ) { + $value[ $key ] = $this->order( $val, $order ); + } + return $value; } /** diff --git a/views/admin-page.php b/views/admin-page.php index 25f5b7501..3a5f6eb13 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -7,7 +7,7 @@ // TODO: This pre-populates the option with previous weeks and months values. // This should be moved to a separate function that can be called from the admin page. -foreach ( [ 1, 2, 3, 4, 5 ] as $prpl_i ) { +foreach ( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] as $prpl_i ) { \ProgressPlanner\Progress_Planner::get_instance() ->get_settings() ->update_value_previous_unsaved_interval( 'weeks', $prpl_i ); @@ -17,7 +17,7 @@ } ?> - +

@@ -29,60 +29,94 @@

label ); ?>

- - - - - - - - - - - - - +
+
+ get_settings()->get_value( [ 'stats' ], 'ASC' ); + $data = [ + 'labels' => [], + 'datasets' => [ [ 'data' => [] ] ], + ]; + foreach ( $prpl_settings as $year => $prpl_setting ) { + if ( ! isset( $prpl_setting['weeks'] ) ) { + continue; + } + foreach ( $prpl_setting['weeks'] as $week => $prpl_week ) { + $data['labels'][] = $year . 'W' . $week; + foreach ( $prpl_week['posts'] as $post_type => $nr ) { + if ( $prpl_post_type === $post_type ) { + $data['datasets'][0]['data'][] = $nr; + } + } + } + } + \ProgressPlanner\Progress_Planner::get_instance()->get_admin()->get_chart()->render_chart( + $prpl_post_type, + 'line', + $data, + [ 'scales' => [ 'y' => [ 'beginAtZero' => true ] ] ] + ); + ?> +
+
- - - - - -
- get_settings()->get_value( - 'stats', - (int) gmdate( - 'Y', - strtotime( '-' . $prpl_interval_value . ' ' . $prpl_interval_type ) - ), - $prpl_interval_type, - (int) gmdate( - ( 'weeks' === $prpl_interval_type ) ? 'W' : 'n', - strtotime( '-' . $prpl_interval_value . ' ' . $prpl_interval_type ) - ), - 'posts', - $prpl_post_type - ) - ); - ?> - - get_settings()->get_value( - 'stats', - gmdate( 'Y', strtotime( '-' . $prpl_interval_value . ' ' . $prpl_interval_type ) ), - $prpl_interval_type, - gmdate( 'n', strtotime( '-' . $prpl_interval_value . ' ' . $prpl_interval_type ) ), - 'words', - $prpl_post_type - ) - ); - ?> -
+ + + + + + + + + + + + + + - - -
+ + + + + +
+ get_settings()->get_value( + [ + 'stats', + (int) gmdate( + 'Y', + strtotime( '-' . $prpl_interval_value . ' ' . $prpl_interval_type ) + ), + $prpl_interval_type, + (int) gmdate( + ( 'weeks' === $prpl_interval_type ) ? 'W' : 'n', + strtotime( '-' . $prpl_interval_value . ' ' . $prpl_interval_type ) + ), + 'posts', + $prpl_post_type, + ] + ) + ); + ?> + + get_settings()->get_value( + [ + 'stats', + gmdate( 'Y', strtotime( '-' . $prpl_interval_value . ' ' . $prpl_interval_type ) ), + $prpl_interval_type, + gmdate( 'n', strtotime( '-' . $prpl_interval_value . ' ' . $prpl_interval_type ) ), + 'words', + $prpl_post_type, + ] + ) + ); + ?> +


+ +
From 27132bc22e2ec499c367a987964b2c02ec6eb70c Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 8 Feb 2024 14:02:29 +0200 Subject: [PATCH 030/490] CS & cleanup --- includes/admin/class-chart.php | 26 +++++--------------------- views/admin-page.php | 19 +++++++++---------- 2 files changed, 14 insertions(+), 31 deletions(-) diff --git a/includes/admin/class-chart.php b/includes/admin/class-chart.php index 8041d237e..2c7f15124 100644 --- a/includes/admin/class-chart.php +++ b/includes/admin/class-chart.php @@ -12,27 +12,6 @@ */ class Chart { - /** - * Constructor. - */ - public function __construct() { - $this->register_hooks(); - } - - /** - * Register the hooks. - */ - private function register_hooks() { - \add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); - } - - /** - * Enqueue the scripts and styles. - */ - public function enqueue_scripts() { - \wp_enqueue_script( 'chartjs', 'https://cdn.jsdelivr.net/npm/chart.js', [], '4.4.1', true ); - } - /** * Render the chart. * @@ -45,7 +24,12 @@ public function enqueue_scripts() { */ public function render_chart( $id, $type, $data, $options ) { $id = 'progress-planner-chart-' . $id; + + // TODO: This should be properly enqueued. + // phpcs:ignore + echo ''; ?> +

@@ -32,20 +31,20 @@
get_settings()->get_value( [ 'stats' ], 'ASC' ); - $data = [ + $prpl_settings = \ProgressPlanner\Progress_Planner::get_instance()->get_settings()->get_value( [ 'stats' ], 'ASC' ); + $prpl_chart_data = [ 'labels' => [], 'datasets' => [ [ 'data' => [] ] ], ]; - foreach ( $prpl_settings as $year => $prpl_setting ) { + foreach ( $prpl_settings as $prpl_chart_data_year => $prpl_setting ) { if ( ! isset( $prpl_setting['weeks'] ) ) { continue; } - foreach ( $prpl_setting['weeks'] as $week => $prpl_week ) { - $data['labels'][] = $year . 'W' . $week; - foreach ( $prpl_week['posts'] as $post_type => $nr ) { - if ( $prpl_post_type === $post_type ) { - $data['datasets'][0]['data'][] = $nr; + foreach ( $prpl_setting['weeks'] as $prpl_week_nr => $prpl_week ) { + $prpl_chart_data['labels'][] = $prpl_chart_data_year . 'W' . $prpl_week_nr; + foreach ( $prpl_week['posts'] as $prpl_pt => $prpl_chart_nr ) { + if ( $prpl_post_type === $prpl_pt ) { + $prpl_chart_data['datasets'][0]['data'][] = $prpl_chart_nr; } } } @@ -53,7 +52,7 @@ \ProgressPlanner\Progress_Planner::get_instance()->get_admin()->get_chart()->render_chart( $prpl_post_type, 'line', - $data, + $prpl_chart_data, [ 'scales' => [ 'y' => [ 'beginAtZero' => true ] ] ] ); ?> From 759d7400f69d6fa861e3de1fd40a940ab03a3bc8 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 9 Feb 2024 16:04:55 +0200 Subject: [PATCH 031/490] Refactor almost everything. Still buggy, WIP --- assets/css/admin.css | 5 + assets/js/admin.js | 109 ++++++++++ includes/admin/class-page.php | 96 +++++++++ includes/class-admin.php | 10 - includes/{admin => }/class-chart.php | 4 +- includes/class-progress-planner.php | 21 +- includes/class-settings.php | 192 ------------------ includes/class-stats.php | 1 - .../stats/class-stat-posts-prepopulate.php | 159 +++++++++++++++ includes/stats/class-stat-posts.php | 154 ++++++++++++-- includes/stats/class-stat-terms.php | 41 ---- includes/stats/class-stat.php | 93 +++++++-- progress-planner.php | 1 + views/admin-page.php | 157 +++++--------- 14 files changed, 643 insertions(+), 400 deletions(-) create mode 100644 assets/css/admin.css create mode 100644 assets/js/admin.js rename includes/{admin => }/class-chart.php (91%) delete mode 100644 includes/class-settings.php create mode 100644 includes/stats/class-stat-posts-prepopulate.php delete mode 100644 includes/stats/class-stat-terms.php diff --git a/assets/css/admin.css b/assets/css/admin.css new file mode 100644 index 000000000..2e230ca43 --- /dev/null +++ b/assets/css/admin.css @@ -0,0 +1,5 @@ +#progress-planner-scan-progress progress{ + width: 100%; + max-width: 500px; + min-height: 1px; +} diff --git a/assets/js/admin.js b/assets/js/admin.js new file mode 100644 index 000000000..6f5bd23c2 --- /dev/null +++ b/assets/js/admin.js @@ -0,0 +1,109 @@ +/** + * Loaded on edit-tags admin pages, this file contains the JavaScript for the ProgressPlanner plugin. + * + * @file This files contains the functionality for the ProgressPlanner plugin. + * @author Joost de Valk + */ + +/* global progressPlanner, tb_remove */ + +/** + * A helper to make AJAX requests. + * + * @param {Object} params The callback parameters. + * @param {string} params.url The URL to send the request to. + * @param {Object} params.data The data to send with the request. + * @param {Function} params.successAction The callback to run on success. + * @param {Function} params.failAction The callback to run on failure. + */ +const progressPlannerAjaxRequest = ( { url, data, successAction, failAction } ) => { + const http = new XMLHttpRequest(); + http.open( 'POST', url, true ); + http.onreadystatechange = () => { + let response; + try { + response = JSON.parse( http.response ); + } catch ( e ) { + if ( http.readyState === 4 && http.status !== 200 ) { + // eslint-disable-next-line no-console + console.warn( http, e ); + return http.response; + } + } + if ( http.readyState === 4 && http.status === 200 ) { + return successAction ? successAction( response ) : response; + } + return failAction ? failAction( response ) : response; + }; + + const dataForm = new FormData(); + + // eslint-disable-next-line prefer-const + for ( let [ key, value ] of Object.entries( data ) ) { + dataForm.append( key, value ); + } + + http.send( dataForm ); +}; + +const progressPlannerTriggerScan = () => { + document.getElementById( 'progress-planner-scan-progress' ).style.display = 'block'; + progressPlannerAjaxRequest( { + url: progressPlanner.ajaxUrl, + data: { + action: 'progress_planner_scan_posts', + _ajax_nonce: progressPlanner.nonce, + }, + successAction: ( response ) => { + document.querySelector( '#progress-planner-scan-progress progress' ).value = response.data.progress; + + progressPlannerTriggerScan(); + if ( response.data.progress >= 100 ) { + location.reload(); + } + }, + } ); +}; + +/** + * Similar to jQuery's $( document ).ready(). + * Runs a callback when the DOM is ready. + * + * @param {Function} callback The callback to run when the DOM is ready. + */ +function progressPlannerDomReady( callback ) { + if ( document.readyState !== 'loading' ) { + callback(); + return; + } + document.addEventListener( 'DOMContentLoaded', callback ); +} + +progressPlannerDomReady( () => { + const scanForm = document.getElementById( 'progress-planner-scan' ); + const resetForm = document.getElementById( 'progress-planner-stats-reset' ); + if ( scanForm ) { + scanForm.addEventListener( 'submit', ( e ) => { + e.preventDefault(); + progressPlannerTriggerScan(); + } ); + } + if ( resetForm ) { + resetForm.addEventListener( 'submit', ( e ) => { + e.preventDefault(); + resetForm.querySelector( 'input[type="submit"]' ).disabled = true; + progressPlannerAjaxRequest( { + url: progressPlanner.ajaxUrl, + data: { + action: 'progress_planner_reset_stats', + _ajax_nonce: progressPlanner.nonce, + }, + successAction: ( response ) => { + resetForm.querySelector( 'input[type="submit"]' ).value = progressPlanner.l10n.resettingStats; + // Refresh the page. + location.reload(); + }, + } ); + } ); + } +} ); diff --git a/includes/admin/class-page.php b/includes/admin/class-page.php index c624aea82..ffbce7679 100644 --- a/includes/admin/class-page.php +++ b/includes/admin/class-page.php @@ -7,6 +7,8 @@ namespace ProgressPlanner\Admin; +use PROGRESS_PLANNER_URL; + /** * Admin page class. */ @@ -24,6 +26,9 @@ public function __construct() { */ private function register_hooks() { \add_action( 'admin_menu', [ $this, 'add_page' ] ); + \add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); + \add_action( 'wp_ajax_progress_planner_scan_posts', [ $this, 'ajax_scan' ] ); + \add_action( 'wp_ajax_progress_planner_reset_stats', [ $this, 'ajax_reset_stats' ] ); } /** @@ -46,4 +51,95 @@ public function add_page() { public function render_page() { include PROGRESS_PLANNER_DIR . '/views/admin-page.php'; } + + /** + * Enqueue scripts and styles. + * + * @param string $hook The current admin page. + */ + public function enqueue_scripts( $hook ) { + if ( 'toplevel_page_progress-planner' !== $hook ) { + return; + } + + \wp_enqueue_script( + 'progress-planner-admin', + PROGRESS_PLANNER_URL . 'assets/js/admin.js', + [], + filemtime( PROGRESS_PLANNER_DIR . '/assets/js/admin.js' ), + true + ); + + // Localize the script. + \wp_localize_script( + 'progress-planner-admin', + 'progressPlanner', + [ + 'ajaxUrl' => \admin_url( 'admin-ajax.php' ), + 'nonce' => \wp_create_nonce( 'progress_planner_scan' ), + 'l10n' => [ + 'resettingStats' => \esc_html__( 'Resetting stats...', 'progress-planner' ), + ], + ] + ); + + \wp_enqueue_style( + 'progress-planner-admin', + PROGRESS_PLANNER_URL . 'assets/css/admin.css', + [], + filemtime( PROGRESS_PLANNER_DIR . '/assets/css/admin.css' ) + ); + } + + /** + * Ajax scan. + */ + public function ajax_scan() { + // Check the nonce. + if ( ! \check_ajax_referer( 'progress_planner_scan', 'nonce', false ) ) { + \wp_send_json_error( [ 'message' => \esc_html__( 'Invalid nonce.', 'progress-planner' ) ] ); + } + + // Scan the posts. + $prepopulate = new \ProgressPlanner\Stats\Stat_Posts_Prepopulate(); + $prepopulate->prepopulate(); + + // Get the total pages. + $total_pages = $prepopulate->get_total_pages(); + + // Get the last page. + $last_page = $prepopulate->get_last_prepopulated_page(); + + \wp_send_json_success( + [ + 'totalPages' => $total_pages, + 'lastPage' => $last_page, + 'isComplete' => $prepopulate->is_prepopulating_complete(), + 'progress' => round( ( $last_page / $total_pages ) * 100 ), + 'messages' => [ + 'scanComplete' => \esc_html__( 'Scan complete.', 'progress-planner' ), + ], + ] + ); + } + + /** + * Ajax reset stats. + */ + public function ajax_reset_stats() { + // Check the nonce. + if ( ! \check_ajax_referer( 'progress_planner_scan', 'nonce', false ) ) { + \wp_send_json_error( [ 'message' => \esc_html__( 'Invalid nonce.', 'progress-planner' ) ] ); + } + + // Reset the stats. + $stats = new \ProgressPlanner\Stats\Stat_Posts(); + $stats->reset_stats(); + + \wp_send_json_success( + [ + 'message' => \esc_html__( 'Stats reset. Refreshing the page...', 'progress-planner' ), + ] + ); + } } diff --git a/includes/class-admin.php b/includes/class-admin.php index da0531a06..cc2f89e9a 100644 --- a/includes/class-admin.php +++ b/includes/class-admin.php @@ -24,7 +24,6 @@ class Admin { */ public function __construct() { $this->admin_page = new Admin\Page(); - $this->chart = new Admin\Chart(); } /** @@ -35,13 +34,4 @@ public function __construct() { public function get_admin_page() { return $this->admin_page; } - - /** - * Get the chart object. - * - * @return \ProgressPlanner\Admin\Chart - */ - public function get_chart() { - return $this->chart; - } } diff --git a/includes/admin/class-chart.php b/includes/class-chart.php similarity index 91% rename from includes/admin/class-chart.php rename to includes/class-chart.php index 2c7f15124..63971517c 100644 --- a/includes/admin/class-chart.php +++ b/includes/class-chart.php @@ -5,7 +5,7 @@ * @package ProgressPlanner */ -namespace ProgressPlanner\Admin; +namespace ProgressPlanner; /** * Render a chart. @@ -35,7 +35,7 @@ public function render_chart( $id, $type, $data, $options ) { var chart = new Chart( document.getElementById( '' ), { type: '', data: , - options: , + // options: , } ); admin = new Admin(); - $this->settings = new Settings(); - $this->stats = new Stats(); - } - - /** - * Get the settings object. - * - * @return \ProgressPlanner\Settings - */ - public function get_settings() { - return $this->settings; + $this->admin = new Admin(); + $this->stats = new Stats(); } /** diff --git a/includes/class-settings.php b/includes/class-settings.php deleted file mode 100644 index f813fea08..000000000 --- a/includes/class-settings.php +++ /dev/null @@ -1,192 +0,0 @@ - ['b' => 'c']], get_value('a', 'b') will return 'c'. - * If the key does not exist, it will return null. - * If no keys are provided, it will return the entire array. - * @param string $order The order. Can be "ASC" or "DESC". - * If null, then the order will be the same as the saved value. - * - * @return array - */ - public function get_value( $args, $order = null ) { - // Get the saved value. - $saved_value = \get_option( $this->option_name, [] ); - - // Get the value for current week & month. - $current_value = $this->get_current_value(); - - // Merge the saved value with the default value. - $value = \array_replace_recursive( $current_value, $saved_value ); - - $value = empty( $args ) - ? $value - : \_wp_array_get( $value, $args ); - - return null === $order - ? $value - : $this->order( $value, $order ); - } - - /** - * Get the value, ordered by date. - * - * @param mixed $value The value. - * @param string $order The order. Can be "ASC" or "DESC". - * - * @return array - */ - public function order( $value, $order = 'ASC' ) { - if ( ! is_array( $value ) ) { - return $value; - } - - // Order the array. - if ( 'ASC' === $order ) { - \ksort( $value ); - } else { - \krsort( $value ); - } - - foreach ( $value as $key => $val ) { - $value[ $key ] = $this->order( $val, $order ); - } - return $value; - } - - /** - * Update the option value. - * - * @param string[] $args The keys to update. - * This will go over the array recursively, updating the value for the last key. - * See get_value for more info. - * @param mixed $value The new value. - * - * @return bool Returns the result of the update_option function. - */ - public function set_value( $args, $value ) { - // Get the saved value. - $saved_value = \get_option( $this->option_name, [] ); - - // Update item in the array. - \_wp_array_set( $saved_value, $args, $value ); - - // Update the option value. - return \update_option( $this->option_name, $saved_value ); - } - - /** - * Get the value for the current week & month. - * - * @return array - */ - private function get_current_value() { - // Get the values for current week and month. - $curr_y = (int) \gmdate( 'Y' ); - $curr_m = (int) \gmdate( 'n' ); - $curr_w = (int) \gmdate( 'W' ); - $curr_value = []; - $stats = Progress_Planner::get_instance()->get_stats()->get_stat( 'posts' ); - - foreach ( \array_keys( \get_post_types( [ 'public' => true ] ) ) as $post_type ) { - // Set the post-type. - $stats->set_post_type( $post_type ); - - // Get weekly stats. - $week_stats = $stats->set_date_query( - [ - [ - 'after' => '-1 week', - 'inclusive' => true, - ], - ] - )->get_data(); - - // Set weekly stats. - \_wp_array_set( $curr_value, [ 'stats', $curr_y, 'weeks', $curr_w, 'posts', $post_type ], $week_stats['count'] ); - \_wp_array_set( $curr_value, [ 'stats', $curr_y, 'weeks', $curr_w, 'words', $post_type ], $week_stats['word_count'] ); - - // Get monthly stats. - $month_stats = $stats->set_date_query( - [ - [ - 'after' => gmdate( 'F Y' ), - 'inclusive' => true, - ], - ] - )->get_data(); - - // Set monthly stats. - \_wp_array_set( $curr_value, [ 'stats', $curr_y, 'months', $curr_m, 'posts', $post_type ], $month_stats['count'] ); - \_wp_array_set( $curr_value, [ 'stats', $curr_y, 'months', $curr_m, 'words', $post_type ], $month_stats['word_count'] ); - } - - return $curr_value; - } - - /** - * Update value for a previous, unsaved week. - * - * @param string $interval_type The interval type. Can be "week" or "month". - * @param int $interval_value The number of weeks or months back to update the value for. - * - * @return void - */ - public function update_value_previous_unsaved_interval( $interval_type = 'weeks', $interval_value = 0 ) { - - // Get the year & week numbers for the defined week/month. - $year = (int) \gmdate( 'Y', strtotime( "-$interval_value $interval_type" ) ); - $interval_type_nr = (int) \gmdate( - 'weeks' === $interval_type ? 'W' : 'n', - strtotime( "-$interval_value $interval_type" ) - ); - - $stats = Progress_Planner::get_instance()->get_stats()->get_stat( 'posts' ); - foreach ( \array_keys( \get_post_types( [ 'public' => true ] ) ) as $post_type ) { - $interval_stats = $stats->set_post_type( $post_type )->set_date_query( - [ - [ - 'after' => '-' . ( $interval_value + 1 ) . ' ' . $interval_type, - 'inclusive' => true, - ], - [ - 'before' => '-' . $interval_value . ' ' . $interval_type, - 'inclusive' => false, - ], - ] - )->get_data(); - - $this->set_value( - [ 'stats', $year, $interval_type, $interval_type_nr, 'posts', $post_type ], - $interval_stats['count'] - ); - $this->set_value( - [ 'stats', $year, $interval_type, $interval_type_nr, 'words', $post_type ], - $interval_stats['word_count'] - ); - } - } -} diff --git a/includes/class-stats.php b/includes/class-stats.php index f89b19300..6dc7ee91f 100644 --- a/includes/class-stats.php +++ b/includes/class-stats.php @@ -62,6 +62,5 @@ public function get_stat( $id ) { */ private function register_stats() { $this->add_stat( 'posts', new Stats\Stat_Posts() ); - $this->add_stat( 'terms', new Stats\Stat_Terms() ); } } diff --git a/includes/stats/class-stat-posts-prepopulate.php b/includes/stats/class-stat-posts-prepopulate.php new file mode 100644 index 000000000..47a4b4fb2 --- /dev/null +++ b/includes/stats/class-stat-posts-prepopulate.php @@ -0,0 +1,159 @@ +last_page = $this->get_last_prepopulated_page(); + } + + /** + * Get the last page that was prepopulated from the API. + * + * @return int + */ + public function get_last_prepopulated_page() { + $option_value = $this->get_value(); + + return ( isset( $option_value[ self::LAST_PAGE_KEY ] ) ) + ? $option_value[ self::LAST_PAGE_KEY ] + : 0; + } + + /** + * Get the total number of pages that need to be prepopulated. + * + * @return int + */ + public function get_total_pages() { + + $post_types = array_keys( \get_post_types( [ 'public' => true ] ) ); + $total = 0; + + foreach ( $post_types as $post_type ) { + $total += (int) \wp_count_posts( $post_type )->publish; + } + + // Calculate the total number of pages. + return (int) ceil( $total / $this->posts_per_page ); + } + + /** + * Set the last page that was prepopulated from the API. + * + * @param int $page The page number. + * + * @return void + */ + private function set_last_prepopulated_page( $page ) { + $option_value = $this->get_value(); + + $option_value[ self::LAST_PAGE_KEY ] = $page; + $this->set_value( [], $option_value ); + } + + /** + * Whether prepopulating is complete. + * + * @return bool + */ + public function is_prepopulating_complete() { + $option_value = $this->get_value(); + if ( + isset( $option_value[ self::FINISHED_KEY ] ) && + $option_value[ self::FINISHED_KEY ] + ) { + // Remove the last page key. It's no longer needed. + if ( isset( $option_value[ self::LAST_PAGE_KEY ] ) ) { + unset( $option_value[ self::LAST_PAGE_KEY ] ); + $this->set_value( [], $option_value ); + } + return true; + } + return false; + } + + /** + * Get posts and prepopulate the stats. + * + * @return void + */ + public function prepopulate() { + // Bail early if prepopulating is complete. + if ( $this->is_prepopulating_complete() ) { + return; + } + $posts = \get_posts( + [ + 'posts_per_page' => $this->posts_per_page, + 'paged' => $this->last_page + 1, + 'post_type' => array_keys( \get_post_types( [ 'public' => true ] ) ), + 'post_status' => 'publish', + 'suppress_filters' => false, + // Start from oldest to newest. + 'order' => 'ASC', + 'orderby' => 'date', + ] + ); + + // If there are no posts for this page, then prepopulating is complete. + if ( empty( $posts ) ) { + $option_value = $this->get_value(); + + $option_value[ self::FINISHED_KEY ] = true; + $this->set_value( [], $option_value ); + return; + } + + // Save the posts stats. + foreach ( $posts as $post ) { + $this->save_post( $post ); + } + + // Set the last page that was prepopulated from the API. + $this->set_last_prepopulated_page( $this->last_page + 1 ); + } +} diff --git a/includes/stats/class-stat-posts.php b/includes/stats/class-stat-posts.php index 1d90f619d..1f4b943bc 100644 --- a/includes/stats/class-stat-posts.php +++ b/includes/stats/class-stat-posts.php @@ -7,6 +7,8 @@ namespace ProgressPlanner\Stats; +use ProgressPlanner\Chart; + /** * Stats about posts. */ @@ -19,6 +21,13 @@ class Stat_Posts extends Stat { */ protected $post_type = 'post'; + /** + * The stat type. This is used as a key in the settings array. + * + * @var string + */ + protected $type = 'posts'; + /** * Set the post-type for this stat. * @@ -32,31 +41,140 @@ public function set_post_type( $post_type ) { } /** - * Get the data. + * Save a post to the stats. + * + * @param \WP_Post $post The post. + */ + protected function save_post( $post ) { + // Get the date. + $date = (int) gmdate( 'Ymd', strtotime( $post->post_date ) ); + + // Add the post to the stats. + $this->set_value( + [ $date, $post->ID ], + [ + 'post_type' => $post->post_type, + 'words' => \str_word_count( $post->post_content ), + ], + ); + } + + /** + * Get stats for date range. + * + * @param string $start_date The start date. + * @param string $end_date The end date. + * @param array $post_types The post types. * * @return array */ - public function get_data() { - $args = [ - 'posts_per_page' => 1000, // phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page - 'post_type' => $this->post_type, - 'post_status' => 'publish', - 'date_query' => $this->date_query, - 'suppress_filters' => false, - ]; + public function get_stats( $start_date, $end_date, $post_types = [] ) { + $stats = $this->get_value(); - $posts = get_posts( $args ); + // Format the start and end dates. + $start_date = (int) gmdate( 'Ymd', strtotime( $start_date ) ); + $end_date = (int) gmdate( 'Ymd', strtotime( $end_date ) ); - // Get the number of words. - $word_count = 0; - foreach ( $posts as $post ) { - $word_count += str_word_count( $post->post_content ); + // Get the stats for the date range and post types. + foreach ( array_keys( $stats ) as $key ) { + // Remove the stats that are outside the date range. + if ( $key <= $start_date || $key > $end_date ) { + unset( $stats[ $key ] ); + continue; + } + + // If we have not defined post types, then we don't need to filter by post type. + if ( empty( $post_types ) ) { + continue; + } + + // Remove the stats that are not in the post types. + foreach ( $stats[ $key ] as $post_id => $details ) { + if ( ! \in_array( $details['post_type'], $post_types, true ) ) { + unset( $stats[ $key ][ $post_id ] ); + } + } } - return [ - 'count' => count( $posts ), - 'post_ids' => \wp_list_pluck( $posts, 'ID' ), - 'word_count' => $word_count, + // Filter out empty dates. + $stats = \array_filter( $stats ); + + return $stats; + } + + /** + * Build a chart for the stats. + * + * @param array $post_types The post types. + * @param string $context The context for the chart. Can be 'count' or 'words'. + * @param string $interval The interval for the chart. Can be 'days', 'weeks', 'months', 'years'. + * @param int $range The number of intervals to show. + * @param int $offset The offset for the intervals. + */ + public function build_chart( $post_types = [], $context = 'count', $interval = 'weeks', $range = 10, $offset = 0 ) { + $post_types = empty( $post_types ) + ? array_keys( \get_post_types( [ 'public' => true ] ) ) + : $post_types; + + $range_array_end = \range( $offset, $range - 1 ); + $range_array_start = \range( $offset + 1, $range ); + \krsort( $range_array_start ); + \krsort( $range_array_end ); + + $range_array = \array_combine( $range_array_start, $range_array_end ); + + $data = [ + 'labels' => [], + 'datasets' => [], ]; + $datasets = []; + $post_type_count_totals = []; + foreach ( $post_types as $post_type ) { + $post_type_count_totals[ $post_type ] = 0; + $datasets[ $post_type ] = [ + 'label' => \get_post_type_object( $post_type )->label, + 'data' => [], + ]; + } + + foreach ( $range_array as $start => $end ) { + $stats = $this->get_stats( "-$start $interval", "-$end $interval", $post_types ); + + // TODO: Format the date depending on the user's locale. + $data['labels'][] = gmdate( 'Y-m-d', strtotime( "-$start $interval" ) ); + + foreach ( $post_types as $post_type ) { + foreach ( $stats as $posts ) { + foreach ( $posts as $post_details ) { + if ( $post_details['post_type'] === $post_type ) { + if ( 'words' === $context ) { + $post_type_count_totals[ $post_type ] += $post_details['words']; + continue; + } + ++$post_type_count_totals[ $post_type ]; + } + } + } + $datasets[ $post_type ]['data'][] = $post_type_count_totals[ $post_type ]; + } + } + $data['datasets'] = \array_values( $datasets ); + + $chart = new Chart(); + $chart->render_chart( + md5( wp_json_encode( [ $post_types, $context, $interval, $range, $offset ] ) ), + 'line', + $data, + [] + ); + } + + /** + * Reset the stats in our database. + * + * @return void + */ + public function reset_stats() { + $this->set_value( [], [] ); } } diff --git a/includes/stats/class-stat-terms.php b/includes/stats/class-stat-terms.php deleted file mode 100644 index 9eca97630..000000000 --- a/includes/stats/class-stat-terms.php +++ /dev/null @@ -1,41 +0,0 @@ -taxonomy = $taxonomy; - } - - /** - * Get the stat data. - * - * @return array - */ - public function get_data() { - return [ - 'total' => (array) \wp_count_terms( [ 'taxonomy' => $this->taxonomy ] ), - ]; - } -} diff --git a/includes/stats/class-stat.php b/includes/stats/class-stat.php index 4377cd3da..356388fd1 100644 --- a/includes/stats/class-stat.php +++ b/includes/stats/class-stat.php @@ -2,7 +2,7 @@ /** * An object containing info about an individual stat. * - * This is an abstract class, meant to be extended by individual stat classes. + * This object is meant to be extended by individual stat classes. * * @package ProgressPlanner */ @@ -12,9 +12,35 @@ /** * An object containing info about an individual stat. * - * This is an abstract class, meant to be extended by individual stat classes. + * This object is meant to be extended by individual stat classes. */ -abstract class Stat { +class Stat { + + /** + * The setting name. + */ + const SETTING_NAME = 'progress_planner_stats'; + + /** + * The stat type. This is used as a key in the settings array. + * + * @var string + */ + protected $type; + + /** + * The stats setting value. + * + * @var array + */ + protected $stats; + + /** + * The value. + * + * @var array + */ + protected $value; /** * Date Query. @@ -26,21 +52,64 @@ abstract class Stat { protected $date_query = []; /** - * Set the date query. + * Constructor. + */ + public function __construct() { + $this->value = $this->get_value(); + } + + /** + * Get the value. * - * @param array $date_query The date query. + * @param array $index The index. This is an array of keys, which will be used to get the value. + * This will go over the array recursively, getting the value for the last key. + * See _wp_array_get for more info. + * @return mixed + */ + public function get_value( $index = [] ) { + if ( $this->value ) { + return $this->value; + } + + if ( ! isset( $this->stats[ $this->type ] ) ) { + $this->stats = \get_option( self::SETTING_NAME, [ $this->type => [] ] ); + } + + if ( ! empty( $index ) ) { + return \_wp_array_get( $this->stats[ $this->type ], $index ); + } + + return $this->stats[ $this->type ]; + } + + /** + * Set the value. * - * @return Stat Returns this object to allow chaining methods. + * @param array $index The index. This is an array of keys, which will be used to set the value. + * This will go over the array recursively, updating the value for the last key. + * See _wp_array_set for more info. + * @param mixed $value The value. */ - public function set_date_query( $date_query ) { - $this->date_query = $date_query; - return $this; + public function set_value( $index, $value ) { + // Call $this->get_value, to populate $this->stats. + $this->get_value(); + + // Add $this->type to the beginning of the index array. + \array_unshift( $index, $this->type ); + + // Update the value in the array. + \_wp_array_set( $this->stats, $index, $value ); + + // Save the option. + \update_option( self::SETTING_NAME, $this->stats ); } /** - * Get the stat data. + * Set the date query. * - * @return array + * @param array $date_query The date query. */ - abstract public function get_data(); + public function set_date_query( $date_query ) { + $this->date_query = $date_query; + } } diff --git a/progress-planner.php b/progress-planner.php index cd32120b8..d7be3d221 100644 --- a/progress-planner.php +++ b/progress-planner.php @@ -6,6 +6,7 @@ */ define( 'PROGRESS_PLANNER_DIR', __DIR__ ); +define( 'PROGRESS_PLANNER_URL', plugin_dir_url( __FILE__ ) ); require_once PROGRESS_PLANNER_DIR . '/includes/autoload.php'; diff --git a/views/admin-page.php b/views/admin-page.php index 3cb390588..aa3f7c7e2 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -5,117 +5,64 @@ * @package ProgressPlanner */ -// TODO: This pre-populates the option with previous weeks and months values. -// This should be moved to a separate function that can be called from the admin page. -foreach ( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] as $prpl_i ) { - \ProgressPlanner\Progress_Planner::get_instance() - ->get_settings() - ->update_value_previous_unsaved_interval( 'weeks', $prpl_i ); - \ProgressPlanner\Progress_Planner::get_instance() - ->get_settings() - ->update_value_previous_unsaved_interval( 'months', $prpl_i ); -} +// TODO: Move this to a method to allow prepopulating stats from the admin page. +$prpl_prepopulate = new ProgressPlanner\Stats\Stat_Posts_Prepopulate(); + +// Get the stats object. +$prpl_stats_posts = new ProgressPlanner\Stats\Stat_Posts(); + +// var_dump($prpl_stats_posts->get_value()); +// Check if we have a scan pending. +$prpl_scan_pending = false; +$prpl_scan_progress = 0; +if ( ! $prpl_stats_posts->get_value( $prpl_prepopulate::FINISHED_KEY ) ) { + $prpl_scan_pending = true; +} ?>

-

+ + +

+

+
+ +
+ + + +
+ +
- - $prpl_post_type_object ) : ?> - public ) : ?> - - -

label ); ?>

-
-
- get_settings()->get_value( [ 'stats' ], 'ASC' ); - $prpl_chart_data = [ - 'labels' => [], - 'datasets' => [ [ 'data' => [] ] ], - ]; - foreach ( $prpl_settings as $prpl_chart_data_year => $prpl_setting ) { - if ( ! isset( $prpl_setting['weeks'] ) ) { - continue; - } - foreach ( $prpl_setting['weeks'] as $prpl_week_nr => $prpl_week ) { - $prpl_chart_data['labels'][] = $prpl_chart_data_year . 'W' . $prpl_week_nr; - foreach ( $prpl_week['posts'] as $prpl_pt => $prpl_chart_nr ) { - if ( $prpl_post_type === $prpl_pt ) { - $prpl_chart_data['datasets'][0]['data'][] = $prpl_chart_nr; - } - } - } - } - \ProgressPlanner\Progress_Planner::get_instance()->get_admin()->get_chart()->render_chart( - $prpl_post_type, - 'line', - $prpl_chart_data, - [ 'scales' => [ 'y' => [ 'beginAtZero' => true ] ] ] - ); - ?> +

+
+
+

+ build_chart( [], 'count', 'weeks', 10, 0 ); ?> +
+
+

+ build_chart( [], 'words', 'weeks', 10, 0 ); ?>
- - - - - - - - - - - - - - - - -
- - - - - -
- get_settings()->get_value( - [ - 'stats', - (int) gmdate( - 'Y', - strtotime( '-' . $prpl_interval_value . ' ' . $prpl_interval_type ) - ), - $prpl_interval_type, - (int) gmdate( - ( 'weeks' === $prpl_interval_type ) ? 'W' : 'n', - strtotime( '-' . $prpl_interval_value . ' ' . $prpl_interval_type ) - ), - 'posts', - $prpl_post_type, - ] - ) - ); - ?> - - get_settings()->get_value( - [ - 'stats', - gmdate( 'Y', strtotime( '-' . $prpl_interval_value . ' ' . $prpl_interval_type ) ), - $prpl_interval_type, - gmdate( 'n', strtotime( '-' . $prpl_interval_value . ' ' . $prpl_interval_type ) ), - 'words', - $prpl_post_type, - ] - ) - ); - ?> -

- +
From 6a7c324afecca27d8896a16e8d8a4f06368203cc Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 12 Feb 2024 10:02:12 +0200 Subject: [PATCH 032/490] use a const --- includes/stats/class-stat-posts-prepopulate.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/stats/class-stat-posts-prepopulate.php b/includes/stats/class-stat-posts-prepopulate.php index 47a4b4fb2..409b0e0bf 100644 --- a/includes/stats/class-stat-posts-prepopulate.php +++ b/includes/stats/class-stat-posts-prepopulate.php @@ -17,7 +17,7 @@ class Stat_Posts_Prepopulate extends Stat_Posts { * * @var int */ - private $posts_per_page = 100; + const POSTS_PER_PAGE = 10; /** * Key used to store the last page that was prepopulated from the API. @@ -78,7 +78,7 @@ public function get_total_pages() { } // Calculate the total number of pages. - return (int) ceil( $total / $this->posts_per_page ); + return (int) ceil( $total / self::POSTS_PER_PAGE ); } /** @@ -128,7 +128,7 @@ public function prepopulate() { } $posts = \get_posts( [ - 'posts_per_page' => $this->posts_per_page, + 'posts_per_page' => self::POSTS_PER_PAGE, 'paged' => $this->last_page + 1, 'post_type' => array_keys( \get_post_types( [ 'public' => true ] ) ), 'post_status' => 'publish', From 285d9aa80f94a5a59219c9bc970b4cea30bb7380 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 12 Feb 2024 10:02:42 +0200 Subject: [PATCH 033/490] Use mysql2date instead of gmdate --- includes/stats/class-stat-posts.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/stats/class-stat-posts.php b/includes/stats/class-stat-posts.php index 1f4b943bc..3a65e5df0 100644 --- a/includes/stats/class-stat-posts.php +++ b/includes/stats/class-stat-posts.php @@ -47,7 +47,7 @@ public function set_post_type( $post_type ) { */ protected function save_post( $post ) { // Get the date. - $date = (int) gmdate( 'Ymd', strtotime( $post->post_date ) ); + $date = (int) mysql2date( 'Ymd', $post->post_date ); // Add the post to the stats. $this->set_value( From f091cfb2b7e72d1d19eefa0fa7560133a5b6bd26 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 12 Feb 2024 10:04:13 +0200 Subject: [PATCH 034/490] add debug for the option --- views/admin-page.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/views/admin-page.php b/views/admin-page.php index aa3f7c7e2..eebeae0d8 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -53,6 +53,15 @@ +
+ +
+ +
get_value() ); ?>
+
+ +
+

From 5275f9c4f80e466730ad48128831d1b72b76ebce Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 12 Feb 2024 14:29:07 +0200 Subject: [PATCH 035/490] Prepopulation now works. --- assets/js/admin.js | 40 +++-- includes/admin/class-page.php | 17 +- includes/class-chart.php | 8 +- .../stats/class-stat-posts-prepopulate.php | 149 ++++++------------ includes/stats/class-stat-posts.php | 18 ++- includes/stats/class-stat.php | 7 +- views/admin-page.php | 64 +++++--- 7 files changed, 155 insertions(+), 148 deletions(-) diff --git a/assets/js/admin.js b/assets/js/admin.js index 6f5bd23c2..8b46bda75 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -1,11 +1,8 @@ /** * Loaded on edit-tags admin pages, this file contains the JavaScript for the ProgressPlanner plugin. - * - * @file This files contains the functionality for the ProgressPlanner plugin. - * @author Joost de Valk */ -/* global progressPlanner, tb_remove */ +/* global progressPlanner */ /** * A helper to make AJAX requests. @@ -48,20 +45,39 @@ const progressPlannerAjaxRequest = ( { url, data, successAction, failAction } ) const progressPlannerTriggerScan = () => { document.getElementById( 'progress-planner-scan-progress' ).style.display = 'block'; + const successAction = ( response ) => { + const progressBar = document.querySelector( '#progress-planner-scan-progress progress' ); + // Update the progressbar. + if ( response.data.progress > progressBar.value ) { + progressBar.value = response.data.progress; + } + + // Refresh the page when scan has finished. + if ( response.data.progress >= 100 ) { + location.reload(); + return; + } + + progressPlannerTriggerScan(); + }; + const failAction = ( response ) => { + if ( response && response.data && response.data.progress ) { + successAction( response ); + return; + } + // Wait 1 second and re-trigger. + setTimeout( () => { + progressPlannerTriggerScan(); + }, 1000 ); + }; progressPlannerAjaxRequest( { url: progressPlanner.ajaxUrl, data: { action: 'progress_planner_scan_posts', _ajax_nonce: progressPlanner.nonce, }, - successAction: ( response ) => { - document.querySelector( '#progress-planner-scan-progress progress' ).value = response.data.progress; - - progressPlannerTriggerScan(); - if ( response.data.progress >= 100 ) { - location.reload(); - } - }, + successAction: successAction, + failAction: failAction, } ); }; diff --git a/includes/admin/class-page.php b/includes/admin/class-page.php index ffbce7679..2546a1b53 100644 --- a/includes/admin/class-page.php +++ b/includes/admin/class-page.php @@ -104,19 +104,18 @@ public function ajax_scan() { $prepopulate = new \ProgressPlanner\Stats\Stat_Posts_Prepopulate(); $prepopulate->prepopulate(); - // Get the total pages. - $total_pages = $prepopulate->get_total_pages(); + // Get the last scanned post ID. + $last_scanned_id = $prepopulate->get_last_prepopulated_post(); - // Get the last page. - $last_page = $prepopulate->get_last_prepopulated_page(); + // Get the last post-ID that exists on the site. + $last_post_id = $prepopulate->get_last_post_id(); \wp_send_json_success( [ - 'totalPages' => $total_pages, - 'lastPage' => $last_page, - 'isComplete' => $prepopulate->is_prepopulating_complete(), - 'progress' => round( ( $last_page / $total_pages ) * 100 ), - 'messages' => [ + 'lastScanned' => $last_scanned_id, + 'lastPost' => $last_post_id, + 'progress' => round( ( $last_scanned_id / $last_post_id ) * 100 ), + 'messages' => [ 'scanComplete' => \esc_html__( 'Scan complete.', 'progress-planner' ), ], ] diff --git a/includes/class-chart.php b/includes/class-chart.php index 63971517c..01408b651 100644 --- a/includes/class-chart.php +++ b/includes/class-chart.php @@ -22,20 +22,22 @@ class Chart { * * @return void */ - public function render_chart( $id, $type, $data, $options ) { + public function render_chart( $id, $type, $data, $options = [] ) { $id = 'progress-planner-chart-' . $id; + $options['responsive'] = true; + // TODO: This should be properly enqueued. // phpcs:ignore echo ''; ?> - + last_page = $this->get_last_prepopulated_page(); - } + private $last_scanned_post_id = 0; /** * Get the last page that was prepopulated from the API. * * @return int */ - public function get_last_prepopulated_page() { - $option_value = $this->get_value(); - - return ( isset( $option_value[ self::LAST_PAGE_KEY ] ) ) - ? $option_value[ self::LAST_PAGE_KEY ] - : 0; - } - - /** - * Get the total number of pages that need to be prepopulated. - * - * @return int - */ - public function get_total_pages() { - - $post_types = array_keys( \get_post_types( [ 'public' => true ] ) ); - $total = 0; - - foreach ( $post_types as $post_type ) { - $total += (int) \wp_count_posts( $post_type )->publish; + public function get_last_prepopulated_post() { + if ( $this->last_scanned_post_id ) { + return $this->last_scanned_post_id; } - // Calculate the total number of pages. - return (int) ceil( $total / self::POSTS_PER_PAGE ); + $option_value = $this->get_value(); + foreach ( $option_value as $posts ) { + foreach ( $posts as $post_id => $details ) { + if ( $post_id > $this->last_scanned_post_id ) { + $this->last_scanned_post_id = $post_id; + } + } + } + return $this->last_scanned_post_id; } /** - * Set the last page that was prepopulated from the API. - * - * @param int $page The page number. + * Get posts and prepopulate the stats. * * @return void */ - private function set_last_prepopulated_page( $page ) { - $option_value = $this->get_value(); + public function prepopulate() { + // Get the last post we processed. + $last_id = $this->get_last_prepopulated_post(); - $option_value[ self::LAST_PAGE_KEY ] = $page; - $this->set_value( [], $option_value ); - } + // Build an array of posts to save. + $post_ids = \range( $last_id, $last_id + self::POSTS_PER_PAGE ); - /** - * Whether prepopulating is complete. - * - * @return bool - */ - public function is_prepopulating_complete() { - $option_value = $this->get_value(); - if ( - isset( $option_value[ self::FINISHED_KEY ] ) && - $option_value[ self::FINISHED_KEY ] - ) { - // Remove the last page key. It's no longer needed. - if ( isset( $option_value[ self::LAST_PAGE_KEY ] ) ) { - unset( $option_value[ self::LAST_PAGE_KEY ] ); - $this->set_value( [], $option_value ); + foreach ( $post_ids as $post_id ) { + $post = get_post( $post_id ); + + // If the post doesn't exist or is not publish, skip it. + if ( ! $post || 'publish' !== $post->post_status ) { + if ( $post ) { + $this->last_scanned_post_id = $post->ID; + } + continue; } - return true; + + $this->save_post( $post ); + $this->last_scanned_post_id = $post->ID; } - return false; } /** - * Get posts and prepopulate the stats. + * Get the last post-ID created. * - * @return void + * @return int */ - public function prepopulate() { - // Bail early if prepopulating is complete. - if ( $this->is_prepopulating_complete() ) { - return; + public function get_last_post_id() { + if ( $this->last_post_id ) { + return $this->last_post_id; } - $posts = \get_posts( + $last_post = \get_posts( [ - 'posts_per_page' => self::POSTS_PER_PAGE, - 'paged' => $this->last_page + 1, - 'post_type' => array_keys( \get_post_types( [ 'public' => true ] ) ), + 'posts_per_page' => 1, + 'post_type' => $this->get_post_types_names(), 'post_status' => 'publish', 'suppress_filters' => false, - // Start from oldest to newest. - 'order' => 'ASC', - 'orderby' => 'date', + 'order' => 'DESC', + 'orderby' => 'ID', ] ); - - // If there are no posts for this page, then prepopulating is complete. - if ( empty( $posts ) ) { - $option_value = $this->get_value(); - - $option_value[ self::FINISHED_KEY ] = true; - $this->set_value( [], $option_value ); - return; + if ( empty( $last_post ) ) { + return 0; } - - // Save the posts stats. - foreach ( $posts as $post ) { - $this->save_post( $post ); - } - - // Set the last page that was prepopulated from the API. - $this->set_last_prepopulated_page( $this->last_page + 1 ); + $this->last_post_id = $last_post[0]->ID; + return $this->last_post_id; } } diff --git a/includes/stats/class-stat-posts.php b/includes/stats/class-stat-posts.php index 3a65e5df0..a864c0260 100644 --- a/includes/stats/class-stat-posts.php +++ b/includes/stats/class-stat-posts.php @@ -44,8 +44,11 @@ public function set_post_type( $post_type ) { * Save a post to the stats. * * @param \WP_Post $post The post. + * + * @return bool */ protected function save_post( $post ) { + // error_log( $post->post_date . ' => ' . mysql2date( 'Ymd', $post->post_date ) ); // Get the date. $date = (int) mysql2date( 'Ymd', $post->post_date ); @@ -113,7 +116,7 @@ public function get_stats( $start_date, $end_date, $post_types = [] ) { */ public function build_chart( $post_types = [], $context = 'count', $interval = 'weeks', $range = 10, $offset = 0 ) { $post_types = empty( $post_types ) - ? array_keys( \get_post_types( [ 'public' => true ] ) ) + ? $this->get_post_types_names() : $post_types; $range_array_end = \range( $offset, $range - 1 ); @@ -177,4 +180,17 @@ public function build_chart( $post_types = [], $context = 'count', $interval = ' public function reset_stats() { $this->set_value( [], [] ); } + + /** + * Get an array of post-types names for the stats. + * + * @return array + */ + public function get_post_types_names() { + $post_types = \get_post_types( [ 'public' => true ] ); + unset( $post_types['attachment'] ); + + return array_keys( $post_types ); + } + } diff --git a/includes/stats/class-stat.php b/includes/stats/class-stat.php index 356388fd1..1d89fbb63 100644 --- a/includes/stats/class-stat.php +++ b/includes/stats/class-stat.php @@ -92,16 +92,17 @@ public function get_value( $index = [] ) { */ public function set_value( $index, $value ) { // Call $this->get_value, to populate $this->stats. - $this->get_value(); + $stats = \get_option( self::SETTING_NAME, [ $this->type => [] ] ); // Add $this->type to the beginning of the index array. \array_unshift( $index, $this->type ); // Update the value in the array. - \_wp_array_set( $this->stats, $index, $value ); + \_wp_array_set( $stats, $index, $value ); // Save the option. - \update_option( self::SETTING_NAME, $this->stats ); + \update_option( self::SETTING_NAME, $stats ); + $this->stats = $stats; } /** diff --git a/views/admin-page.php b/views/admin-page.php index eebeae0d8..c7ca8cb53 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -11,12 +11,19 @@ // Get the stats object. $prpl_stats_posts = new ProgressPlanner\Stats\Stat_Posts(); -// var_dump($prpl_stats_posts->get_value()); +// Values for the graph filters. +$prpl_filters_intervals = [ + 'days' => __( 'Days', 'progress-planner' ), + 'weeks' => __( 'Weeks', 'progress-planner' ), + 'months' => __( 'Months', 'progress-planner' ), +]; +$prpl_filters_interval = isset( $_POST['interval'] ) ? sanitize_key( $_POST['interval'] ) : 'weeks'; +$prpl_filters_number = isset( $_POST['number'] ) ? (int) $_POST['number'] : 10; // Check if we have a scan pending. $prpl_scan_pending = false; $prpl_scan_progress = 0; -if ( ! $prpl_stats_posts->get_value( $prpl_prepopulate::FINISHED_KEY ) ) { +if ( empty( $prpl_stats_posts->get_value() ) ) { $prpl_scan_pending = true; } ?> @@ -44,34 +51,49 @@ /** * The scan is not pending. * - * Show a form to reset the stats (while we're still in development). - * - * Show the stats. + * Show the stats, and at the end a form to reset the stats + * (while we're still in development). */ ?> +
+

+
+ + + +
+
+ +
+ +

+
+

+ build_chart( [], 'count', $prpl_filters_interval, $prpl_filters_number, 0 ); ?> +
+
+

+ build_chart( [], 'words', $prpl_filters_interval, $prpl_filters_number, 0 ); ?> +
+ +
+
-
-
- +
get_value() ); ?>
-
- -

-
-
-

- build_chart( [], 'count', 'weeks', 10, 0 ); ?> -
-
-

- build_chart( [], 'words', 'weeks', 10, 0 ); ?> -
-
+ Date: Tue, 13 Feb 2024 09:29:43 +0200 Subject: [PATCH 036/490] minor tweaks & fixes --- assets/js/admin.js | 43 +++++++++++++++++-- .../stats/class-stat-posts-prepopulate.php | 2 +- includes/stats/class-stat-posts.php | 3 +- views/admin-page.php | 8 ++-- 4 files changed, 47 insertions(+), 9 deletions(-) diff --git a/assets/js/admin.js b/assets/js/admin.js index 8b46bda75..952095146 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -45,6 +45,14 @@ const progressPlannerAjaxRequest = ( { url, data, successAction, failAction } ) const progressPlannerTriggerScan = () => { document.getElementById( 'progress-planner-scan-progress' ).style.display = 'block'; + + /** + * The action to run on a successful AJAX request. + * This function should update the UI and re-trigger the scan if necessary. + * + * @param {Object} response The response from the server. + * The response should contain a `progress` property. + */ const successAction = ( response ) => { const progressBar = document.querySelector( '#progress-planner-scan-progress progress' ); // Update the progressbar. @@ -52,24 +60,42 @@ const progressPlannerTriggerScan = () => { progressBar.value = response.data.progress; } + console.info( `Progress: ${response.data.progress}%, (${response.data.lastScanned}/${response.data.lastPost})` ); + // Refresh the page when scan has finished. if ( response.data.progress >= 100 ) { - location.reload(); + // location.reload(); return; } - progressPlannerTriggerScan(); + // Wait half a second and re-trigger. + setTimeout( () => { + progressPlannerTriggerScan(); + }, 500 ); }; + + /** + * The action to run on a failed AJAX request. + * This function should re-trigger the scan if necessary. + * If the response contains a `progress` property, the successAction should be run instead. + * + * @param {Object} response The response from the server. + */ const failAction = ( response ) => { if ( response && response.data && response.data.progress ) { successAction( response ); return; } - // Wait 1 second and re-trigger. + + // Wait 2 seconds and re-trigger. setTimeout( () => { progressPlannerTriggerScan(); }, 1000 ); }; + + /** + * The AJAX request to run. + */ progressPlannerAjaxRequest( { url: progressPlanner.ajaxUrl, data: { @@ -98,16 +124,27 @@ function progressPlannerDomReady( callback ) { progressPlannerDomReady( () => { const scanForm = document.getElementById( 'progress-planner-scan' ); const resetForm = document.getElementById( 'progress-planner-stats-reset' ); + + /** + * Add an event listener for the scan form. + */ if ( scanForm ) { scanForm.addEventListener( 'submit', ( e ) => { e.preventDefault(); + scanForm.querySelector( 'input[type="submit"]' ).disabled = true; progressPlannerTriggerScan(); } ); } + + /** + * Add an event listener for the reset form. + */ if ( resetForm ) { resetForm.addEventListener( 'submit', ( e ) => { e.preventDefault(); resetForm.querySelector( 'input[type="submit"]' ).disabled = true; + + // Make an AJAX request to reset the stats. progressPlannerAjaxRequest( { url: progressPlanner.ajaxUrl, data: { diff --git a/includes/stats/class-stat-posts-prepopulate.php b/includes/stats/class-stat-posts-prepopulate.php index 238e1bd49..fb3679e52 100644 --- a/includes/stats/class-stat-posts-prepopulate.php +++ b/includes/stats/class-stat-posts-prepopulate.php @@ -17,7 +17,7 @@ class Stat_Posts_Prepopulate extends Stat_Posts { * * @var int */ - const POSTS_PER_PAGE = 30; + const POSTS_PER_PAGE = 100; /** * The last post-ID. diff --git a/includes/stats/class-stat-posts.php b/includes/stats/class-stat-posts.php index a864c0260..e5c178a63 100644 --- a/includes/stats/class-stat-posts.php +++ b/includes/stats/class-stat-posts.php @@ -45,7 +45,7 @@ public function set_post_type( $post_type ) { * * @param \WP_Post $post The post. * - * @return bool + * @return void */ protected function save_post( $post ) { // error_log( $post->post_date . ' => ' . mysql2date( 'Ymd', $post->post_date ) ); @@ -192,5 +192,4 @@ public function get_post_types_names() { return array_keys( $post_types ); } - } diff --git a/views/admin-page.php b/views/admin-page.php index c7ca8cb53..2c13d823d 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -17,8 +17,10 @@ 'weeks' => __( 'Weeks', 'progress-planner' ), 'months' => __( 'Months', 'progress-planner' ), ]; -$prpl_filters_interval = isset( $_POST['interval'] ) ? sanitize_key( $_POST['interval'] ) : 'weeks'; -$prpl_filters_number = isset( $_POST['number'] ) ? (int) $_POST['number'] : 10; +// phpcs:ignore WordPress.Security.NonceVerification.Missing +$prpl_filters_interval = isset( $_POST['interval'] ) ? sanitize_key( $_POST['interval'] ) : 'weeks'; +// phpcs:ignore WordPress.Security.NonceVerification.Missing +$prpl_filters_number = isset( $_POST['number'] ) ? (int) $_POST['number'] : 10; // Check if we have a scan pending. $prpl_scan_pending = false; @@ -67,7 +69,7 @@ - +
From 3250e7de3b6a08af2de2f8397413f64f34e66b12 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 13 Feb 2024 09:32:08 +0200 Subject: [PATCH 037/490] Reload page when prepopulating is finished --- assets/js/admin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/js/admin.js b/assets/js/admin.js index 952095146..20b5ee75a 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -64,7 +64,7 @@ const progressPlannerTriggerScan = () => { // Refresh the page when scan has finished. if ( response.data.progress >= 100 ) { - // location.reload(); + location.reload(); return; } From 40e0b6cb0d37db5933a416850518fd6e6da75f2e Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 13 Feb 2024 09:45:57 +0200 Subject: [PATCH 038/490] Use a short-lived transient to save the last-scanned post. --- .../stats/class-stat-posts-prepopulate.php | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/includes/stats/class-stat-posts-prepopulate.php b/includes/stats/class-stat-posts-prepopulate.php index fb3679e52..656861998 100644 --- a/includes/stats/class-stat-posts-prepopulate.php +++ b/includes/stats/class-stat-posts-prepopulate.php @@ -39,10 +39,19 @@ class Stat_Posts_Prepopulate extends Stat_Posts { * @return int */ public function get_last_prepopulated_post() { + // If we have the last scanned post, return it. if ( $this->last_scanned_post_id ) { return $this->last_scanned_post_id; } + // Try to get the value from the transient. + $cached = \get_transient( 'progress_planner_last_prepopulated_post' ); + if ( $cached ) { + $this->last_scanned_post_id = $cached; + return $this->last_scanned_post_id; + } + + // Get the last scanned post-ID from the stats. $option_value = $this->get_value(); foreach ( $option_value as $posts ) { foreach ( $posts as $post_id => $details ) { @@ -54,6 +63,13 @@ public function get_last_prepopulated_post() { return $this->last_scanned_post_id; } + /** + * Set the last prepopulated post. + */ + public function save_last_prepopulated_post() { + \set_transient( 'progress_planner_last_prepopulated_post', $this->last_scanned_post_id, \HOUR_IN_SECONDS ); + } + /** * Get posts and prepopulate the stats. * @@ -71,14 +87,14 @@ public function prepopulate() { // If the post doesn't exist or is not publish, skip it. if ( ! $post || 'publish' !== $post->post_status ) { - if ( $post ) { - $this->last_scanned_post_id = $post->ID; - } + $this->last_scanned_post_id = $post_id; + $this->save_last_prepopulated_post(); continue; } $this->save_post( $post ); $this->last_scanned_post_id = $post->ID; + $this->save_last_prepopulated_post(); } } From 05a72d55f91245a7be9fc5b74345c7fd6db0e68f Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 13 Feb 2024 14:10:37 +0200 Subject: [PATCH 039/490] Add basic structure for goals --- includes/class-goals.php | 81 ++++++++++++++++ includes/class-progress-planner.php | 17 ++++ includes/goals/class-goal.php | 139 ++++++++++++++++++++++++++++ 3 files changed, 237 insertions(+) create mode 100644 includes/class-goals.php create mode 100644 includes/goals/class-goal.php diff --git a/includes/class-goals.php b/includes/class-goals.php new file mode 100644 index 000000000..3a958dc8b --- /dev/null +++ b/includes/class-goals.php @@ -0,0 +1,81 @@ +register_goals(); + } + + /** + * Add a goal to the collection. + * + * @param Goal $goal The goal object. + */ + public function add_goal( $goal ) { + $this->goals[] = $goal; + } + + /** + * Get all goals. + * + * @return array + */ + public function get_all_goals() { + return $this->goals; + } + + /** + * Get an individual goal. + * + * @param string $id The ID of the goal. + * @return Goal + */ + public function get_goal( $id ) { + foreach ( $this->goals as $goal ) { + if ( $id === $goal->get_details()['id'] ) { + return $goal; + } + } + return new Goals\Goal(); + } + + /** + * Register the individual goals. + */ + private function register_goals() { + $this->add_goal( + new Goals\Goal( + [ + 'id' => 'weekly_post', + 'title' => esc_html__( 'Write a weekly blog post', 'progress-planner' ), + 'description' => '', + 'type' => 'post', + 'frequency' => 'weekly', + 'priority' => 'high', + ] + ) + ); + } +} diff --git a/includes/class-progress-planner.php b/includes/class-progress-planner.php index 36d020e3b..2462cda56 100644 --- a/includes/class-progress-planner.php +++ b/includes/class-progress-planner.php @@ -33,6 +33,13 @@ class Progress_Planner { */ private $admin; + /** + * The Goals object. + * + * @var \ProgressPlanner\Goals + */ + private $goals; + /** * Get the single instance of this class. * @@ -52,6 +59,7 @@ public static function get_instance() { private function __construct() { $this->admin = new Admin(); $this->stats = new Stats(); + $this->goals = new Goals(); } /** @@ -71,4 +79,13 @@ public function get_stats() { public function get_admin() { return $this->admin; } + + /** + * Get the goals object. + * + * @return \ProgressPlanner\Goals + */ + public function get_goals() { + return $this->goals; + } } diff --git a/includes/goals/class-goal.php b/includes/goals/class-goal.php new file mode 100644 index 000000000..ae8fe6d8d --- /dev/null +++ b/includes/goals/class-goal.php @@ -0,0 +1,139 @@ + '', + 'title' => '', + 'description' => '', + 'type' => '', + 'frequency' => '', + 'start_date' => '', + 'end_date' => '', + 'status' => '', + 'priority' => '', + 'progress' => '', + ] + ); + $this->id = $args['id']; + $this->title = $args['title']; + $this->description = $args['description']; + $this->type = $args['type']; + $this->frequency = $args['frequency']; + $this->start_date = $args['start_date']; + $this->end_date = $args['end_date']; + $this->status = $args['status']; + $this->priority = $args['priority']; + $this->progress = $args['progress']; + } + + /** + * Get the goal ID. + * + * @return string + */ + public function get_details() { + return [ + 'id' => $this->id, + 'title' => $this->title, + 'description' => $this->description, + 'type' => $this->type, + 'frequency' => $this->frequency, + 'start_date' => $this->start_date, + 'end_date' => $this->end_date, + 'status' => $this->status, + 'priority' => $this->priority, + 'progress' => $this->progress, + ]; + } +} From 33e3fab25c2a032632edab384ae22f22f875b48f Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 13 Feb 2024 15:04:53 +0200 Subject: [PATCH 040/490] separate chart class, cleanup & fixes --- includes/charts/class-posts.php | 80 ++++++++++++++++++++++++++ includes/class-chart.php | 10 ++-- includes/class-goals.php | 2 +- includes/goals/class-goal.php | 2 +- includes/stats/class-stat-posts.php | 88 +---------------------------- views/admin-page.php | 20 ++++++- 6 files changed, 106 insertions(+), 96 deletions(-) create mode 100644 includes/charts/class-posts.php diff --git a/includes/charts/class-posts.php b/includes/charts/class-posts.php new file mode 100644 index 000000000..9971ae075 --- /dev/null +++ b/includes/charts/class-posts.php @@ -0,0 +1,80 @@ + [], + 'datasets' => [], + ]; + $datasets = []; + $post_type_count_totals = []; + foreach ( $post_types as $post_type ) { + $post_type_count_totals[ $post_type ] = 0; + $datasets[ $post_type ] = [ + 'label' => \get_post_type_object( $post_type )->label, + 'data' => [], + ]; + } + + $stat_posts = new Stat_Posts(); + foreach ( $range_array as $start => $end ) { + $stats = $stat_posts->get_stats( "-$start $interval", "-$end $interval", $post_types ); + + // TODO: Format the date depending on the user's locale. + $data['labels'][] = gmdate( 'Y-m-d', strtotime( "-$start $interval" ) ); + + foreach ( $post_types as $post_type ) { + foreach ( $stats as $posts ) { + foreach ( $posts as $post_details ) { + if ( $post_details['post_type'] === $post_type ) { + if ( 'words' === $context ) { + $post_type_count_totals[ $post_type ] += $post_details['words']; + continue; + } + ++$post_type_count_totals[ $post_type ]; + } + } + } + $datasets[ $post_type ]['data'][] = $post_type_count_totals[ $post_type ]; + } + } + $data['datasets'] = \array_values( $datasets ); + + $this->render_chart( + md5( wp_json_encode( [ $post_types, $context, $interval, $range, $offset ] ) ), + 'line', + $data, + [] + ); + } +} diff --git a/includes/class-chart.php b/includes/class-chart.php index 01408b651..ef6774ca1 100644 --- a/includes/class-chart.php +++ b/includes/class-chart.php @@ -32,12 +32,12 @@ public function render_chart( $id, $type, $data, $options = [] ) { echo ''; ?> - + 'weekly_post', - 'title' => esc_html__( 'Write a weekly blog post', 'progress-planner' ), + 'title' => \esc_html__( 'Write a weekly blog post', 'progress-planner' ), 'description' => '', 'type' => 'post', 'frequency' => 'weekly', diff --git a/includes/goals/class-goal.php b/includes/goals/class-goal.php index ae8fe6d8d..6f0e3b7cc 100644 --- a/includes/goals/class-goal.php +++ b/includes/goals/class-goal.php @@ -90,7 +90,7 @@ class Goal { * @param array $args The goal arguments. */ public function __construct( $args = [] ) { - $args = wp_parse_args( + $args = \wp_parse_args( $args, [ 'id' => '', diff --git a/includes/stats/class-stat-posts.php b/includes/stats/class-stat-posts.php index e5c178a63..9233bf5cd 100644 --- a/includes/stats/class-stat-posts.php +++ b/includes/stats/class-stat-posts.php @@ -7,20 +7,13 @@ namespace ProgressPlanner\Stats; -use ProgressPlanner\Chart; +use ProgressPlanner\Charts\Posts as Posts_Chart; /** * Stats about posts. */ class Stat_Posts extends Stat { - /** - * The post-type for this stat. - * - * @var string - */ - protected $post_type = 'post'; - /** * The stat type. This is used as a key in the settings array. * @@ -28,18 +21,6 @@ class Stat_Posts extends Stat { */ protected $type = 'posts'; - /** - * Set the post-type for this stat. - * - * @param string $post_type The post-type. - * - * @return Stat_Posts Returns this object to allow chaining methods. - */ - public function set_post_type( $post_type ) { - $this->post_type = $post_type; - return $this; - } - /** * Save a post to the stats. * @@ -105,73 +86,6 @@ public function get_stats( $start_date, $end_date, $post_types = [] ) { return $stats; } - /** - * Build a chart for the stats. - * - * @param array $post_types The post types. - * @param string $context The context for the chart. Can be 'count' or 'words'. - * @param string $interval The interval for the chart. Can be 'days', 'weeks', 'months', 'years'. - * @param int $range The number of intervals to show. - * @param int $offset The offset for the intervals. - */ - public function build_chart( $post_types = [], $context = 'count', $interval = 'weeks', $range = 10, $offset = 0 ) { - $post_types = empty( $post_types ) - ? $this->get_post_types_names() - : $post_types; - - $range_array_end = \range( $offset, $range - 1 ); - $range_array_start = \range( $offset + 1, $range ); - \krsort( $range_array_start ); - \krsort( $range_array_end ); - - $range_array = \array_combine( $range_array_start, $range_array_end ); - - $data = [ - 'labels' => [], - 'datasets' => [], - ]; - $datasets = []; - $post_type_count_totals = []; - foreach ( $post_types as $post_type ) { - $post_type_count_totals[ $post_type ] = 0; - $datasets[ $post_type ] = [ - 'label' => \get_post_type_object( $post_type )->label, - 'data' => [], - ]; - } - - foreach ( $range_array as $start => $end ) { - $stats = $this->get_stats( "-$start $interval", "-$end $interval", $post_types ); - - // TODO: Format the date depending on the user's locale. - $data['labels'][] = gmdate( 'Y-m-d', strtotime( "-$start $interval" ) ); - - foreach ( $post_types as $post_type ) { - foreach ( $stats as $posts ) { - foreach ( $posts as $post_details ) { - if ( $post_details['post_type'] === $post_type ) { - if ( 'words' === $context ) { - $post_type_count_totals[ $post_type ] += $post_details['words']; - continue; - } - ++$post_type_count_totals[ $post_type ]; - } - } - } - $datasets[ $post_type ]['data'][] = $post_type_count_totals[ $post_type ]; - } - } - $data['datasets'] = \array_values( $datasets ); - - $chart = new Chart(); - $chart->render_chart( - md5( wp_json_encode( [ $post_types, $context, $interval, $range, $offset ] ) ), - 'line', - $data, - [] - ); - } - /** * Reset the stats in our database. * diff --git a/views/admin-page.php b/views/admin-page.php index 2c13d823d..7a9d4dfae 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -78,11 +78,27 @@

- build_chart( [], 'count', $prpl_filters_interval, $prpl_filters_number, 0 ); ?> + render( + $prpl_stats_posts->get_post_types_names(), + 'count', + $prpl_filters_interval, + $prpl_filters_number, + 0 + ); + ?>

- build_chart( [], 'words', $prpl_filters_interval, $prpl_filters_number, 0 ); ?> + render( + $prpl_stats_posts->get_post_types_names(), + 'words', + $prpl_filters_interval, + $prpl_filters_number, + 0 + ); + ?>

From 66352bbdc7a28a372b13fe4adda36253e3395916 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 14 Feb 2024 13:34:10 +0200 Subject: [PATCH 041/490] refactor to introduce Goals framework --- includes/charts/class-posts.php | 6 +- ...ss-progress-planner.php => class-base.php} | 22 +-- includes/class-goals.php | 73 ++++------ includes/goals/class-goal-posts.php | 26 ++++ includes/goals/class-goal-recurring.php | 131 ++++++++++++++++++ includes/goals/class-goal.php | 47 +++++-- includes/stats/class-stat-posts.php | 5 - progress-planner.php | 2 +- 8 files changed, 230 insertions(+), 82 deletions(-) rename includes/{class-progress-planner.php => class-base.php} (75%) create mode 100644 includes/goals/class-goal-posts.php create mode 100644 includes/goals/class-goal-recurring.php diff --git a/includes/charts/class-posts.php b/includes/charts/class-posts.php index 9971ae075..ee68df359 100644 --- a/includes/charts/class-posts.php +++ b/includes/charts/class-posts.php @@ -48,7 +48,11 @@ public function render( $post_types = [], $context = 'count', $interval = 'weeks $stat_posts = new Stat_Posts(); foreach ( $range_array as $start => $end ) { - $stats = $stat_posts->get_stats( "-$start $interval", "-$end $interval", $post_types ); + $stats = $stat_posts->get_stats( + (int) gmdate( 'Ymd', strtotime( "-$start $interval" ) ), + (int) gmdate( 'Ymd', strtotime( "-$end $interval" ) ), + $post_types + ); // TODO: Format the date depending on the user's locale. $data['labels'][] = gmdate( 'Y-m-d', strtotime( "-$start $interval" ) ); diff --git a/includes/class-progress-planner.php b/includes/class-base.php similarity index 75% rename from includes/class-progress-planner.php rename to includes/class-base.php index 2462cda56..44cf34c56 100644 --- a/includes/class-progress-planner.php +++ b/includes/class-base.php @@ -10,12 +10,12 @@ /** * Main plugin class. */ -class Progress_Planner { +class Base { /** * An instance of this class. * - * @var \ProgressPlanner\Progress_Planner + * @var \ProgressPlanner\Base */ private static $instance; @@ -33,17 +33,10 @@ class Progress_Planner { */ private $admin; - /** - * The Goals object. - * - * @var \ProgressPlanner\Goals - */ - private $goals; - /** * Get the single instance of this class. * - * @return \ProgressPlanner\Progress_Planner + * @return \ProgressPlanner\Base */ public static function get_instance() { if ( null === self::$instance ) { @@ -79,13 +72,4 @@ public function get_stats() { public function get_admin() { return $this->admin; } - - /** - * Get the goals object. - * - * @return \ProgressPlanner\Goals - */ - public function get_goals() { - return $this->goals; - } } diff --git a/includes/class-goals.php b/includes/class-goals.php index 24b767369..44e857f6d 100644 --- a/includes/class-goals.php +++ b/includes/class-goals.php @@ -9,73 +9,56 @@ /** * Goals class. - * - * This is a collection of individual Goal objects. */ -class Goals { - - /** - * The individual goals. - * - * @var array - */ - private $goals = []; +class Goals extends Base { /** * Constructor. */ public function __construct() { - $this->register_goals(); + $this->register_core_goals(); } /** - * Add a goal to the collection. - * - * @param Goal $goal The goal object. + * Register the goals. */ - public function add_goal( $goal ) { - $this->goals[] = $goal; + private function register_core_goals() { + $this->register_weekly_post_goal(); } /** - * Get all goals. - * - * @return array + * Register weekly-post goal. */ - public function get_all_goals() { - return $this->goals; - } + private function register_weekly_post_goal() { + $stats = $this->get_stats(); - /** - * Get an individual goal. - * - * @param string $id The ID of the goal. - * @return Goal - */ - public function get_goal( $id ) { - foreach ( $this->goals as $goal ) { - if ( $id === $goal->get_details()['id'] ) { - return $goal; - } - } - return new Goals\Goal(); - } + // Get the start date for all stats. + $start_date = array_keys( $this->get_stats()->get_stat( 'posts' )->get_value() ); + sort( $start_date ); + $start_date = $start_date[0]; - /** - * Register the individual goals. - */ - private function register_goals() { - $this->add_goal( - new Goals\Goal( + new \ProgressPlanner\Goals\Goal_Recurring( + new \ProgressPlanner\Goals\Goal_Posts( [ 'id' => 'weekly_post', 'title' => \esc_html__( 'Write a weekly blog post', 'progress-planner' ), 'description' => '', - 'type' => 'post', - 'frequency' => 'weekly', + 'status' => 'active', 'priority' => 'high', + 'evaluate' => function ( $goal_object ) use ( $stats ) { + return (bool) count( + $stats->get_stat( 'posts' )->get_stats( + $goal_object->get_details()['start_date'], + $goal_object->get_details()['end_date'], + [ 'post' ] + ) + ); + }, ] - ) + ), + 'weekly', + $start_date, // Beginning of the stats. + gmdate( 'Ymd' ) // Today. ); } } diff --git a/includes/goals/class-goal-posts.php b/includes/goals/class-goal-posts.php new file mode 100644 index 000000000..f58b7e8e9 --- /dev/null +++ b/includes/goals/class-goal-posts.php @@ -0,0 +1,26 @@ +get_details()['evaluate']; + return $callback( $this ); + } +} diff --git a/includes/goals/class-goal-recurring.php b/includes/goals/class-goal-recurring.php new file mode 100644 index 000000000..c271fdd5d --- /dev/null +++ b/includes/goals/class-goal-recurring.php @@ -0,0 +1,131 @@ +goal = $goal; + $this->frequency = $frequency; + $this->start = $start; + $this->end = $end; + } + + /** + * Build an array of occurences for the goal. + * + * @return Goal[] + */ + public function get_occurences() { + if ( ! empty( $this->occurences ) ) { + return $this->occurences; + } + + $ranges = $this->get_date_periods(); + + foreach ( $ranges as $range ) { + $goal = clone $this->goal; + $goal->set_start_date( $range['start'] ); + $goal->set_end_date( $range['end'] ); + $this->occurences[] = $goal; + } + + return $this->occurences; + } + + /** + * Get an array of periods with start and end dates. + * + * @return array + */ + public function get_date_periods() { + $start = \DateTime::createFromFormat( 'Ymd', $this->start ); + $end = \DateTime::createFromFormat( 'Ymd', $this->end ); + $end = $end->modify( '+1 day' ); + + switch ( $this->frequency ) { + case 'daily': + $interval = new \DateInterval( 'P1D' ); + break; + + case 'weekly': + $interval = new \DateInterval( 'P1W' ); + break; + + case 'monthly': + $interval = new \DateInterval( 'P1M' ); + break; + } + + $period = new \DatePeriod( $start, $interval, 100 ); + $dates_array = []; + foreach ( $period as $date ) { + $dates_array[] = $date->format( 'Ymd' ); + } + + $date_ranges = []; + foreach ( $dates_array as $key => $date ) { + if ( isset( $dates_array[ $key + 1 ] ) ) { + $date_ranges[] = [ + 'start' => $date, + 'end' => \DateTime::createFromFormat( 'Ymd', $dates_array[ $key + 1 ] ) + ->modify( '-1 day' ) + ->format( 'Ymd' ), + ]; + } + } + + return $date_ranges; + } +} diff --git a/includes/goals/class-goal.php b/includes/goals/class-goal.php index 6f0e3b7cc..4ce08b6a4 100644 --- a/includes/goals/class-goal.php +++ b/includes/goals/class-goal.php @@ -12,7 +12,7 @@ /** * An object containing info about an individual goal. */ -class Goal { +abstract class Goal { /** * The goal ID. @@ -42,13 +42,6 @@ class Goal { */ protected $type; - /** - * The goal frequency. - * - * @var string - */ - protected $frequency; - /** * The goal start date. * @@ -84,6 +77,13 @@ class Goal { */ protected $progress; + /** + * The goal evaluation function. + * + * @var string|callable + */ + protected $evaluate; + /** * Constructor. * @@ -97,24 +97,24 @@ public function __construct( $args = [] ) { 'title' => '', 'description' => '', 'type' => '', - 'frequency' => '', 'start_date' => '', 'end_date' => '', 'status' => '', 'priority' => '', 'progress' => '', + 'evaluate' => '__return_false', ] ); $this->id = $args['id']; $this->title = $args['title']; $this->description = $args['description']; $this->type = $args['type']; - $this->frequency = $args['frequency']; $this->start_date = $args['start_date']; $this->end_date = $args['end_date']; $this->status = $args['status']; $this->priority = $args['priority']; $this->progress = $args['progress']; + $this->evaluate = $args['evaluate']; } /** @@ -128,12 +128,37 @@ public function get_details() { 'title' => $this->title, 'description' => $this->description, 'type' => $this->type, - 'frequency' => $this->frequency, 'start_date' => $this->start_date, 'end_date' => $this->end_date, 'status' => $this->status, 'priority' => $this->priority, 'progress' => $this->progress, + 'evaluate' => $this->evaluate, ]; } + + /** + * Set the start date. + * + * @param string $start_date The start date. + */ + public function set_start_date( $start_date ) { + $this->start_date = $start_date; + } + + /** + * Set the end date. + * + * @param string $end_date The end date. + */ + public function set_end_date( $end_date ) { + $this->end_date = $end_date; + } + + /** + * Whether the goal is accomplished for a date-range. + * + * @return bool + */ + abstract public function evaluate(); } diff --git a/includes/stats/class-stat-posts.php b/includes/stats/class-stat-posts.php index 9233bf5cd..c8ff13a32 100644 --- a/includes/stats/class-stat-posts.php +++ b/includes/stats/class-stat-posts.php @@ -29,7 +29,6 @@ class Stat_Posts extends Stat { * @return void */ protected function save_post( $post ) { - // error_log( $post->post_date . ' => ' . mysql2date( 'Ymd', $post->post_date ) ); // Get the date. $date = (int) mysql2date( 'Ymd', $post->post_date ); @@ -55,10 +54,6 @@ protected function save_post( $post ) { public function get_stats( $start_date, $end_date, $post_types = [] ) { $stats = $this->get_value(); - // Format the start and end dates. - $start_date = (int) gmdate( 'Ymd', strtotime( $start_date ) ); - $end_date = (int) gmdate( 'Ymd', strtotime( $end_date ) ); - // Get the stats for the date range and post types. foreach ( array_keys( $stats ) as $key ) { // Remove the stats that are outside the date range. diff --git a/progress-planner.php b/progress-planner.php index d7be3d221..f4e629505 100644 --- a/progress-planner.php +++ b/progress-planner.php @@ -10,4 +10,4 @@ require_once PROGRESS_PLANNER_DIR . '/includes/autoload.php'; -\ProgressPlanner\Progress_Planner::get_instance(); +\ProgressPlanner\Base::get_instance(); From 99557cf9c13494029d00406808a257b2af578758 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 14 Feb 2024 13:36:52 +0200 Subject: [PATCH 042/490] bugfix --- includes/class-goals.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/class-goals.php b/includes/class-goals.php index 44e857f6d..8a39d1b34 100644 --- a/includes/class-goals.php +++ b/includes/class-goals.php @@ -10,7 +10,7 @@ /** * Goals class. */ -class Goals extends Base { +class Goals { /** * Constructor. @@ -30,10 +30,10 @@ private function register_core_goals() { * Register weekly-post goal. */ private function register_weekly_post_goal() { - $stats = $this->get_stats(); + $stats = new Stats(); // Get the start date for all stats. - $start_date = array_keys( $this->get_stats()->get_stat( 'posts' )->get_value() ); + $start_date = array_keys( $stats->get_stat( 'posts' )->get_value() ); sort( $start_date ); $start_date = $start_date[0]; From c7ee80b0d53086ea48b45e9cadd76176ada1161b Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 14 Feb 2024 13:41:42 +0200 Subject: [PATCH 043/490] Sort posts stats --- includes/class-goals.php | 7 +------ includes/stats/class-stat-posts.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/includes/class-goals.php b/includes/class-goals.php index 8a39d1b34..78db75a9d 100644 --- a/includes/class-goals.php +++ b/includes/class-goals.php @@ -32,11 +32,6 @@ private function register_core_goals() { private function register_weekly_post_goal() { $stats = new Stats(); - // Get the start date for all stats. - $start_date = array_keys( $stats->get_stat( 'posts' )->get_value() ); - sort( $start_date ); - $start_date = $start_date[0]; - new \ProgressPlanner\Goals\Goal_Recurring( new \ProgressPlanner\Goals\Goal_Posts( [ @@ -57,7 +52,7 @@ private function register_weekly_post_goal() { ] ), 'weekly', - $start_date, // Beginning of the stats. + array_keys( $stats->get_stat( 'posts' )->get_value() )[0], // Beginning of the stats. gmdate( 'Ymd' ) // Today. ); } diff --git a/includes/stats/class-stat-posts.php b/includes/stats/class-stat-posts.php index c8ff13a32..51503c361 100644 --- a/includes/stats/class-stat-posts.php +++ b/includes/stats/class-stat-posts.php @@ -21,6 +21,20 @@ class Stat_Posts extends Stat { */ protected $type = 'posts'; + /** + * Get the value. + * + * @param array $index The index. This is an array of keys, which will be used to get the value. + * This will go over the array recursively, getting the value for the last key. + * See _wp_array_get for more info. + * @return mixed + */ + public function get_value( $index = [] ) { + $value = parent::get_value( $index ); + ksort( $value ); + return $value; + } + /** * Save a post to the stats. * From 80ff6ca927a76101041276b435f4d953143b6640 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 14 Feb 2024 14:12:04 +0200 Subject: [PATCH 044/490] Add a Date class --- includes/charts/class-posts.php | 5 +- includes/class-date.php | 97 +++++++++++++++++++++++++ includes/class-goals.php | 4 +- includes/goals/class-goal-recurring.php | 50 +------------ includes/stats/class-stat-posts.php | 4 +- includes/stats/class-stat.php | 18 ----- 6 files changed, 109 insertions(+), 69 deletions(-) create mode 100644 includes/class-date.php diff --git a/includes/charts/class-posts.php b/includes/charts/class-posts.php index ee68df359..b0f462177 100644 --- a/includes/charts/class-posts.php +++ b/includes/charts/class-posts.php @@ -8,6 +8,7 @@ namespace ProgressPlanner\Charts; use ProgressPlanner\Chart; +use ProgressPlanner\Date; use ProgressPlanner\Stats\Stat_Posts; /** @@ -49,8 +50,8 @@ public function render( $post_types = [], $context = 'count', $interval = 'weeks $stat_posts = new Stat_Posts(); foreach ( $range_array as $start => $end ) { $stats = $stat_posts->get_stats( - (int) gmdate( 'Ymd', strtotime( "-$start $interval" ) ), - (int) gmdate( 'Ymd', strtotime( "-$end $interval" ) ), + (int) gmdate( Date::FORMAT, strtotime( "-$start $interval" ) ), + (int) gmdate( Date::FORMAT, strtotime( "-$end $interval" ) ), $post_types ); diff --git a/includes/class-date.php b/includes/class-date.php new file mode 100644 index 000000000..73ea11e16 --- /dev/null +++ b/includes/class-date.php @@ -0,0 +1,97 @@ + 'Ymd', + * 'end' => 'Ymd', + * 'dates' => [ 'Ymd', 'Ymd', ... ], + * ]. + */ + public function get_range( $start, $end ) { + $start = \DateTime::createFromFormat( $this->format, $start ); + $end = \DateTime::createFromFormat( $this->format, $end ); + + $dates = []; + $range = new \DatePeriod( $start, new \DateInterval( 'P1D' ), $end ); + foreach ( $range as $date ) { + $dates[] = $date->format( $this->format ); + } + + return [ + 'start' => $start->format( $this->format ), + 'end' => $end->format( $this->format ), + 'dates' => $dates, + ]; + } + + /** + * Get an array of periods with start and end dates. + * + * @param string $start The start date. + * @param string $end The end date. + * @param string $frequency The frequency. Can be 'daily', 'weekly', 'monthly'. + * + * @return array + */ + public function get_periods( $start, $end, $frequency ) { + $start = \DateTime::createFromFormat( $this->format, $start ); + $end = \DateTime::createFromFormat( $this->format, $end ); + $end = $end->modify( '+1 day' ); + + switch ( $frequency ) { + case 'daily': + $interval = new \DateInterval( 'P1D' ); + break; + + case 'weekly': + $interval = new \DateInterval( 'P1W' ); + break; + + case 'monthly': + $interval = new \DateInterval( 'P1M' ); + break; + } + + $period = new \DatePeriod( $start, $interval, 100 ); + $dates_array = []; + foreach ( $period as $date ) { + $dates_array[] = $date->format( $this->format ); + } + + $date_ranges = []; + foreach ( $dates_array as $key => $date ) { + if ( isset( $dates_array[ $key + 1 ] ) ) { + $date_ranges[] = $this->get_range( + $date, + \DateTime::createFromFormat( $this->format, $dates_array[ $key + 1 ] ) + ); + } + } + + return $date_ranges; + } +} diff --git a/includes/class-goals.php b/includes/class-goals.php index 78db75a9d..815741993 100644 --- a/includes/class-goals.php +++ b/includes/class-goals.php @@ -7,6 +7,8 @@ namespace ProgressPlanner; +use ProgressPlanner\Date; + /** * Goals class. */ @@ -53,7 +55,7 @@ private function register_weekly_post_goal() { ), 'weekly', array_keys( $stats->get_stat( 'posts' )->get_value() )[0], // Beginning of the stats. - gmdate( 'Ymd' ) // Today. + gmdate( Date::FORMAT ) // Today. ); } } diff --git a/includes/goals/class-goal-recurring.php b/includes/goals/class-goal-recurring.php index c271fdd5d..7e8e7fb78 100644 --- a/includes/goals/class-goal-recurring.php +++ b/includes/goals/class-goal-recurring.php @@ -7,6 +7,8 @@ namespace ProgressPlanner\Goals; +use ProgressPlanner\Date; + /** * A recurring goal. */ @@ -72,7 +74,8 @@ public function get_occurences() { return $this->occurences; } - $ranges = $this->get_date_periods(); + $date = new Date(); + $ranges = $date->get_periods( $this->start, $this->end, $this->frequency ); foreach ( $ranges as $range ) { $goal = clone $this->goal; @@ -83,49 +86,4 @@ public function get_occurences() { return $this->occurences; } - - /** - * Get an array of periods with start and end dates. - * - * @return array - */ - public function get_date_periods() { - $start = \DateTime::createFromFormat( 'Ymd', $this->start ); - $end = \DateTime::createFromFormat( 'Ymd', $this->end ); - $end = $end->modify( '+1 day' ); - - switch ( $this->frequency ) { - case 'daily': - $interval = new \DateInterval( 'P1D' ); - break; - - case 'weekly': - $interval = new \DateInterval( 'P1W' ); - break; - - case 'monthly': - $interval = new \DateInterval( 'P1M' ); - break; - } - - $period = new \DatePeriod( $start, $interval, 100 ); - $dates_array = []; - foreach ( $period as $date ) { - $dates_array[] = $date->format( 'Ymd' ); - } - - $date_ranges = []; - foreach ( $dates_array as $key => $date ) { - if ( isset( $dates_array[ $key + 1 ] ) ) { - $date_ranges[] = [ - 'start' => $date, - 'end' => \DateTime::createFromFormat( 'Ymd', $dates_array[ $key + 1 ] ) - ->modify( '-1 day' ) - ->format( 'Ymd' ), - ]; - } - } - - return $date_ranges; - } } diff --git a/includes/stats/class-stat-posts.php b/includes/stats/class-stat-posts.php index 51503c361..12bffe084 100644 --- a/includes/stats/class-stat-posts.php +++ b/includes/stats/class-stat-posts.php @@ -7,7 +7,7 @@ namespace ProgressPlanner\Stats; -use ProgressPlanner\Charts\Posts as Posts_Chart; +use ProgressPlanner\Date; /** * Stats about posts. @@ -44,7 +44,7 @@ public function get_value( $index = [] ) { */ protected function save_post( $post ) { // Get the date. - $date = (int) mysql2date( 'Ymd', $post->post_date ); + $date = (int) mysql2date( Date::FORMAT, $post->post_date ); // Add the post to the stats. $this->set_value( diff --git a/includes/stats/class-stat.php b/includes/stats/class-stat.php index 1d89fbb63..12e65451f 100644 --- a/includes/stats/class-stat.php +++ b/includes/stats/class-stat.php @@ -42,15 +42,6 @@ class Stat { */ protected $value; - /** - * Date Query. - * - * The date query, which will be then passed-on to the WP_Date_Query object. - * - * @var array - */ - protected $date_query = []; - /** * Constructor. */ @@ -104,13 +95,4 @@ public function set_value( $index, $value ) { \update_option( self::SETTING_NAME, $stats ); $this->stats = $stats; } - - /** - * Set the date query. - * - * @param array $date_query The date query. - */ - public function set_date_query( $date_query ) { - $this->date_query = $date_query; - } } From 8febe19a7ba965781f48316caf7a57161c96af0e Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 14 Feb 2024 14:28:10 +0200 Subject: [PATCH 045/490] Split views --- views/admin-page-debug.php | 17 +++++ views/admin-page-form-filters.php | 32 +++++++++ views/admin-page-form-scan.php | 17 +++++ views/admin-page-posts-count-progress.php | 18 +++++ views/admin-page-words-count-progress.php | 18 +++++ views/admin-page.php | 85 ++--------------------- 6 files changed, 107 insertions(+), 80 deletions(-) create mode 100644 views/admin-page-debug.php create mode 100644 views/admin-page-form-filters.php create mode 100644 views/admin-page-form-scan.php create mode 100644 views/admin-page-posts-count-progress.php create mode 100644 views/admin-page-words-count-progress.php diff --git a/views/admin-page-debug.php b/views/admin-page-debug.php new file mode 100644 index 000000000..51513cb05 --- /dev/null +++ b/views/admin-page-debug.php @@ -0,0 +1,17 @@ + +
+
+ +
+
+
+ +
get_value() ); ?>
+
diff --git a/views/admin-page-form-filters.php b/views/admin-page-form-filters.php new file mode 100644 index 000000000..1aa2c43d9 --- /dev/null +++ b/views/admin-page-form-filters.php @@ -0,0 +1,32 @@ + __( 'Days', 'progress-planner' ), + 'weeks' => __( 'Weeks', 'progress-planner' ), + 'months' => __( 'Months', 'progress-planner' ), +]; + +?> +
+

+
+ + + +
+
diff --git a/views/admin-page-form-scan.php b/views/admin-page-form-scan.php new file mode 100644 index 000000000..07626d5ad --- /dev/null +++ b/views/admin-page-form-scan.php @@ -0,0 +1,17 @@ + +

+

+
+ +
+ diff --git a/views/admin-page-posts-count-progress.php b/views/admin-page-posts-count-progress.php new file mode 100644 index 000000000..a5c29a228 --- /dev/null +++ b/views/admin-page-posts-count-progress.php @@ -0,0 +1,18 @@ +'; +esc_html_e( 'Posts count progress', 'progress-planner' ); +echo ''; + +( new \ProgressPlanner\Charts\Posts() )->render( + $prpl_stats_posts->get_post_types_names(), + 'count', + $prpl_filters_interval, + $prpl_filters_number, + 0 +); diff --git a/views/admin-page-words-count-progress.php b/views/admin-page-words-count-progress.php new file mode 100644 index 000000000..a887f1721 --- /dev/null +++ b/views/admin-page-words-count-progress.php @@ -0,0 +1,18 @@ +'; +esc_html_e( 'Words count progress', 'progress-planner' ); +echo ''; + +( new \ProgressPlanner\Charts\Posts() )->render( + $prpl_stats_posts->get_post_types_names(), + 'words', + $prpl_filters_interval, + $prpl_filters_number, + 0 +); diff --git a/views/admin-page.php b/views/admin-page.php index 7a9d4dfae..10176c093 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -5,18 +5,9 @@ * @package ProgressPlanner */ -// TODO: Move this to a method to allow prepopulating stats from the admin page. -$prpl_prepopulate = new ProgressPlanner\Stats\Stat_Posts_Prepopulate(); - // Get the stats object. $prpl_stats_posts = new ProgressPlanner\Stats\Stat_Posts(); -// Values for the graph filters. -$prpl_filters_intervals = [ - 'days' => __( 'Days', 'progress-planner' ), - 'weeks' => __( 'Weeks', 'progress-planner' ), - 'months' => __( 'Months', 'progress-planner' ), -]; // phpcs:ignore WordPress.Security.NonceVerification.Missing $prpl_filters_interval = isset( $_POST['interval'] ) ? sanitize_key( $_POST['interval'] ) : 'weeks'; // phpcs:ignore WordPress.Security.NonceVerification.Missing @@ -33,84 +24,18 @@

- -

-

-
- -
- + - -
-

-
- - - -
-
- +
- -

-

- render( - $prpl_stats_posts->get_post_types_names(), - 'count', - $prpl_filters_interval, - $prpl_filters_number, - 0 - ); - ?> +
-

- render( - $prpl_stats_posts->get_post_types_names(), - 'words', - $prpl_filters_interval, - $prpl_filters_number, - 0 - ); - ?> +
- -
-
-
- -

-
- -
get_value() ); ?>
-
+
From 43e294f53a48c219a21e3dabb133c4d64a86fc95 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 14 Feb 2024 14:36:35 +0200 Subject: [PATCH 046/490] Add PHPStan --- composer.json | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index d3de0ff35..fafe6df8c 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,10 @@ "wp-coding-standards/wpcs": "^3.0", "phpcompatibility/phpcompatibility-wp": "*", "php-parallel-lint/php-parallel-lint": "^1.3", - "yoast/wp-test-utils": "^1.2" + "yoast/wp-test-utils": "^1.2", + "phpstan/phpstan": "^1.10", + "szepeviktor/phpstan-wordpress": "^1.3", + "phpstan/extension-installer": "^1.3" }, "scripts": { "check-cs": [ @@ -34,7 +37,8 @@ }, "config": { "allow-plugins": { - "dealerdirect/phpcodesniffer-composer-installer": true + "dealerdirect/phpcodesniffer-composer-installer": true, + "phpstan/extension-installer": true } } } From 90085c2c5bf82f68d536edab3acd1b20f95b2f62 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 14 Feb 2024 14:38:06 +0200 Subject: [PATCH 047/490] Fix issues detected by PHPStan --- includes/class-base.php | 7 +++++++ includes/class-date.php | 18 +++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/includes/class-base.php b/includes/class-base.php index 44cf34c56..e5c9786a1 100644 --- a/includes/class-base.php +++ b/includes/class-base.php @@ -33,6 +33,13 @@ class Base { */ private $admin; + /** + * The Goals object. + * + * @var \ProgressPlanner\Goals + */ + private $goals; + /** * Get the single instance of this class. * diff --git a/includes/class-date.php b/includes/class-date.php index 73ea11e16..3aebaf372 100644 --- a/includes/class-date.php +++ b/includes/class-date.php @@ -32,18 +32,18 @@ class Date { * ]. */ public function get_range( $start, $end ) { - $start = \DateTime::createFromFormat( $this->format, $start ); - $end = \DateTime::createFromFormat( $this->format, $end ); + $start = \DateTime::createFromFormat( self::FORMAT, $start ); + $end = \DateTime::createFromFormat( self::FORMAT, $end ); $dates = []; $range = new \DatePeriod( $start, new \DateInterval( 'P1D' ), $end ); foreach ( $range as $date ) { - $dates[] = $date->format( $this->format ); + $dates[] = $date->format( self::FORMAT ); } return [ - 'start' => $start->format( $this->format ), - 'end' => $end->format( $this->format ), + 'start' => $start->format( self::FORMAT ), + 'end' => $end->format( self::FORMAT ), 'dates' => $dates, ]; } @@ -58,8 +58,8 @@ public function get_range( $start, $end ) { * @return array */ public function get_periods( $start, $end, $frequency ) { - $start = \DateTime::createFromFormat( $this->format, $start ); - $end = \DateTime::createFromFormat( $this->format, $end ); + $start = \DateTime::createFromFormat( self::FORMAT, $start ); + $end = \DateTime::createFromFormat( self::FORMAT, $end ); $end = $end->modify( '+1 day' ); switch ( $frequency ) { @@ -79,7 +79,7 @@ public function get_periods( $start, $end, $frequency ) { $period = new \DatePeriod( $start, $interval, 100 ); $dates_array = []; foreach ( $period as $date ) { - $dates_array[] = $date->format( $this->format ); + $dates_array[] = $date->format( self::FORMAT ); } $date_ranges = []; @@ -87,7 +87,7 @@ public function get_periods( $start, $end, $frequency ) { if ( isset( $dates_array[ $key + 1 ] ) ) { $date_ranges[] = $this->get_range( $date, - \DateTime::createFromFormat( $this->format, $dates_array[ $key + 1 ] ) + \DateTime::createFromFormat( self::FORMAT, $dates_array[ $key + 1 ] ) ); } } From 7268a40507d63042a80ed60f10cf0caa9f87dd03 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 15 Feb 2024 12:24:14 +0200 Subject: [PATCH 048/490] PHPStan config + more tweaks & fixes --- composer.json | 7 ++- includes/admin/class-page.php | 32 ++++++++++++- includes/charts/class-posts.php | 2 + includes/class-base.php | 26 +---------- includes/class-date.php | 24 ++++++---- includes/class-goals.php | 17 +++++-- includes/class-stats.php | 14 ++++-- includes/goals/class-goal-recurring.php | 10 ++-- includes/goals/class-goal.php | 6 ++- .../stats/class-stat-posts-prepopulate.php | 2 + includes/stats/class-stat-posts.php | 10 ++-- includes/stats/class-stat.php | 46 ++++++++----------- phpstan.neon.dist | 11 +++++ views/admin-page-debug.php | 2 +- views/admin-page-form-filters.php | 8 ++-- views/admin-page-form-scan.php | 2 +- views/admin-page-posts-count-progress.php | 6 +-- views/admin-page-words-count-progress.php | 6 +-- views/admin-page.php | 16 +------ 19 files changed, 135 insertions(+), 112 deletions(-) create mode 100644 phpstan.neon.dist diff --git a/composer.json b/composer.json index fafe6df8c..05fb464cc 100644 --- a/composer.json +++ b/composer.json @@ -32,8 +32,11 @@ "@php -r \"exit( intval( is_null( json_decode( file_get_contents( './.wordpress-org/blueprints/blueprint.json' ) ) ) ) );\"" ], "test": [ - "@php ./vendor/phpunit/phpunit/phpunit" - ] + "@php ./vendor/phpunit/phpunit/phpunit" + ], + "phpstan": [ + "@php ./vendor/bin/phpstan analyse --memory-limit=2048M" + ] }, "config": { "allow-plugins": { diff --git a/includes/admin/class-page.php b/includes/admin/class-page.php index 2546a1b53..6e33ea4fe 100644 --- a/includes/admin/class-page.php +++ b/includes/admin/class-page.php @@ -7,8 +7,6 @@ namespace ProgressPlanner\Admin; -use PROGRESS_PLANNER_URL; - /** * Admin page class. */ @@ -23,6 +21,8 @@ public function __construct() { /** * Register the hooks. + * + * @return void */ private function register_hooks() { \add_action( 'admin_menu', [ $this, 'add_page' ] ); @@ -33,6 +33,8 @@ private function register_hooks() { /** * Add the admin page. + * + * @return void */ public function add_page() { \add_menu_page( @@ -47,6 +49,8 @@ public function add_page() { /** * Render the admin page. + * + * @return void */ public function render_page() { include PROGRESS_PLANNER_DIR . '/views/admin-page.php'; @@ -56,6 +60,8 @@ public function render_page() { * Enqueue scripts and styles. * * @param string $hook The current admin page. + * + * @return void */ public function enqueue_scripts( $hook ) { if ( 'toplevel_page_progress-planner' !== $hook ) { @@ -93,6 +99,8 @@ public function enqueue_scripts( $hook ) { /** * Ajax scan. + * + * @return void */ public function ajax_scan() { // Check the nonce. @@ -124,6 +132,8 @@ public function ajax_scan() { /** * Ajax reset stats. + * + * @return void */ public function ajax_reset_stats() { // Check the nonce. @@ -141,4 +151,22 @@ public function ajax_reset_stats() { ] ); } + + /** + * Get params for the admin page. + * + * @return array The params. + */ + public static function get_params() { + static $stats = null; + if ( null === $stats ) { + $stats = new \ProgressPlanner\Stats\Stat_Posts(); + } + return [ + 'stats' => $stats, + 'filter_interval' => isset( $_POST['interval'] ) ? sanitize_key( $_POST['interval'] ) : 'weeks', + 'filter_number' => isset( $_POST['number'] ) ? (int) $_POST['number'] : 10, + 'scan_pending' => empty( $stats->get_value() ), + ]; + } } diff --git a/includes/charts/class-posts.php b/includes/charts/class-posts.php index b0f462177..bd3beb41a 100644 --- a/includes/charts/class-posts.php +++ b/includes/charts/class-posts.php @@ -24,6 +24,8 @@ class Posts extends Chart { * @param string $interval The interval for the chart. Can be 'days', 'weeks', 'months', 'years'. * @param int $range The number of intervals to show. * @param int $offset The offset for the intervals. + * + * @return void */ public function render( $post_types = [], $context = 'count', $interval = 'weeks', $range = 10, $offset = 0 ) { $range_array_end = \range( $offset, $range - 1 ); diff --git a/includes/class-base.php b/includes/class-base.php index e5c9786a1..08120cec7 100644 --- a/includes/class-base.php +++ b/includes/class-base.php @@ -19,13 +19,6 @@ class Base { */ private static $instance; - /** - * The Stats object. - * - * @var \ProgressPlanner\Stats - */ - private $stats; - /** * The Admin object. * @@ -33,13 +26,6 @@ class Base { */ private $admin; - /** - * The Goals object. - * - * @var \ProgressPlanner\Goals - */ - private $goals; - /** * Get the single instance of this class. * @@ -58,17 +44,9 @@ public static function get_instance() { */ private function __construct() { $this->admin = new Admin(); - $this->stats = new Stats(); - $this->goals = new Goals(); - } - /** - * Get the stats object. - * - * @return \ProgressPlanner\Stats - */ - public function get_stats() { - return $this->stats; + new Stats(); + new Goals(); } /** diff --git a/includes/class-date.php b/includes/class-date.php index 3aebaf372..1b8d10892 100644 --- a/includes/class-date.php +++ b/includes/class-date.php @@ -22,8 +22,8 @@ class Date { /** * Get a range of dates. * - * @param string $start The start date. - * @param string $end The end date. + * @param string|int $start The start date. + * @param string|int $end The end date. * * @return array [ * 'start' => 'Ymd', @@ -51,9 +51,9 @@ public function get_range( $start, $end ) { /** * Get an array of periods with start and end dates. * - * @param string $start The start date. - * @param string $end The end date. - * @param string $frequency The frequency. Can be 'daily', 'weekly', 'monthly'. + * @param int|string $start The start date. + * @param int|string $end The end date. + * @param string $frequency The frequency. Can be 'daily', 'weekly', 'monthly'. * * @return array */ @@ -67,13 +67,13 @@ public function get_periods( $start, $end, $frequency ) { $interval = new \DateInterval( 'P1D' ); break; - case 'weekly': - $interval = new \DateInterval( 'P1W' ); - break; - case 'monthly': $interval = new \DateInterval( 'P1M' ); break; + + default: // Default to weekly. + $interval = new \DateInterval( 'P1W' ); + break; } $period = new \DatePeriod( $start, $interval, 100 ); @@ -85,9 +85,13 @@ public function get_periods( $start, $end, $frequency ) { $date_ranges = []; foreach ( $dates_array as $key => $date ) { if ( isset( $dates_array[ $key + 1 ] ) ) { + $datetime = \DateTime::createFromFormat( self::FORMAT, $dates_array[ $key + 1 ] ); + if ( ! $datetime ) { + continue; + } $date_ranges[] = $this->get_range( $date, - \DateTime::createFromFormat( self::FORMAT, $dates_array[ $key + 1 ] ) + $datetime->format( self::FORMAT ) ); } } diff --git a/includes/class-goals.php b/includes/class-goals.php index 815741993..d2bb8ec67 100644 --- a/includes/class-goals.php +++ b/includes/class-goals.php @@ -8,6 +8,9 @@ namespace ProgressPlanner; use ProgressPlanner\Date; +use ProgressPlanner\Stats\Stat_Posts; +use ProgressPlanner\Goals\Goal_Recurring; +use ProgressPlanner\Goals\Goal_Posts; /** * Goals class. @@ -23,6 +26,8 @@ public function __construct() { /** * Register the goals. + * + * @return void */ private function register_core_goals() { $this->register_weekly_post_goal(); @@ -30,12 +35,14 @@ private function register_core_goals() { /** * Register weekly-post goal. + * + * @return void */ private function register_weekly_post_goal() { - $stats = new Stats(); + $stats = new Stat_Posts(); - new \ProgressPlanner\Goals\Goal_Recurring( - new \ProgressPlanner\Goals\Goal_Posts( + new Goal_Recurring( + new Goal_Posts( [ 'id' => 'weekly_post', 'title' => \esc_html__( 'Write a weekly blog post', 'progress-planner' ), @@ -44,7 +51,7 @@ private function register_weekly_post_goal() { 'priority' => 'high', 'evaluate' => function ( $goal_object ) use ( $stats ) { return (bool) count( - $stats->get_stat( 'posts' )->get_stats( + $stats->get_stats( $goal_object->get_details()['start_date'], $goal_object->get_details()['end_date'], [ 'post' ] @@ -54,7 +61,7 @@ private function register_weekly_post_goal() { ] ), 'weekly', - array_keys( $stats->get_stat( 'posts' )->get_value() )[0], // Beginning of the stats. + array_keys( $stats->get_value() )[0], // Beginning of the stats. gmdate( Date::FORMAT ) // Today. ); } diff --git a/includes/class-stats.php b/includes/class-stats.php index 6dc7ee91f..52c8b87c9 100644 --- a/includes/class-stats.php +++ b/includes/class-stats.php @@ -7,6 +7,9 @@ namespace ProgressPlanner; +use ProgressPlanner\Stats\Stat; +use ProgressPlanner\Stats\Stat_Posts; + /** * Stats class. * @@ -33,8 +36,10 @@ public function __construct() { * * @param string $id The ID of the stat. * @param Stat $stat The stat object. + * + * @return void */ - public function add_stat( $id, $stat ) { + public function add_stat( $id, Stat $stat ) { $this->stats[ $id ] = $stat; } @@ -51,16 +56,19 @@ public function get_all_stats() { * Get an individual stat. * * @param string $id The ID of the stat. + * * @return Stat */ - public function get_stat( $id ) { + public function get_stat( $id ): Stat { return $this->stats[ $id ]; } /** * Register the individual stats. + * + * @return void */ private function register_stats() { - $this->add_stat( 'posts', new Stats\Stat_Posts() ); + $this->add_stat( 'posts', new Stat_Posts() ); } } diff --git a/includes/goals/class-goal-recurring.php b/includes/goals/class-goal-recurring.php index 7e8e7fb78..869dceea7 100644 --- a/includes/goals/class-goal-recurring.php +++ b/includes/goals/class-goal-recurring.php @@ -31,21 +31,21 @@ class Goal_Recurring { /** * The start date. * - * @var string + * @var int|string */ private $start; /** * The end date. * - * @var string + * @var int|string */ private $end; /** * An array of occurences. * - * @var array + * @var Goal[] */ private $occurences = []; @@ -54,8 +54,8 @@ class Goal_Recurring { * * @param \ProgressPlanner\Goals\Goal $goal The goal object. * @param string $frequency The goal frequency. - * @param string $start The start date. - * @param string $end The end date. + * @param int|string $start The start date. + * @param int|string $end The end date. */ public function __construct( $goal, $frequency, $start, $end ) { $this->goal = $goal; diff --git a/includes/goals/class-goal.php b/includes/goals/class-goal.php index 4ce08b6a4..4a2974322 100644 --- a/includes/goals/class-goal.php +++ b/includes/goals/class-goal.php @@ -120,7 +120,7 @@ public function __construct( $args = [] ) { /** * Get the goal ID. * - * @return string + * @return array */ public function get_details() { return [ @@ -141,6 +141,8 @@ public function get_details() { * Set the start date. * * @param string $start_date The start date. + * + * @return void */ public function set_start_date( $start_date ) { $this->start_date = $start_date; @@ -150,6 +152,8 @@ public function set_start_date( $start_date ) { * Set the end date. * * @param string $end_date The end date. + * + * @return void */ public function set_end_date( $end_date ) { $this->end_date = $end_date; diff --git a/includes/stats/class-stat-posts-prepopulate.php b/includes/stats/class-stat-posts-prepopulate.php index 656861998..6b35c4c6c 100644 --- a/includes/stats/class-stat-posts-prepopulate.php +++ b/includes/stats/class-stat-posts-prepopulate.php @@ -65,6 +65,8 @@ public function get_last_prepopulated_post() { /** * Set the last prepopulated post. + * + * @return void */ public function save_last_prepopulated_post() { \set_transient( 'progress_planner_last_prepopulated_post', $this->last_scanned_post_id, \HOUR_IN_SECONDS ); diff --git a/includes/stats/class-stat-posts.php b/includes/stats/class-stat-posts.php index 12bffe084..aff5a39c3 100644 --- a/includes/stats/class-stat-posts.php +++ b/includes/stats/class-stat-posts.php @@ -24,7 +24,7 @@ class Stat_Posts extends Stat { /** * Get the value. * - * @param array $index The index. This is an array of keys, which will be used to get the value. + * @param string[]|int[] $index The index. This is an array of keys, which will be used to get the value. * This will go over the array recursively, getting the value for the last key. * See _wp_array_get for more info. * @return mixed @@ -59,9 +59,9 @@ protected function save_post( $post ) { /** * Get stats for date range. * - * @param string $start_date The start date. - * @param string $end_date The end date. - * @param array $post_types The post types. + * @param int|string $start_date The start date. + * @param int|string $end_date The end date. + * @param string[] $post_types The post types. * * @return array */ @@ -107,7 +107,7 @@ public function reset_stats() { /** * Get an array of post-types names for the stats. * - * @return array + * @return string[] */ public function get_post_types_names() { $post_types = \get_post_types( [ 'public' => true ] ); diff --git a/includes/stats/class-stat.php b/includes/stats/class-stat.php index 12e65451f..252a156e1 100644 --- a/includes/stats/class-stat.php +++ b/includes/stats/class-stat.php @@ -35,33 +35,17 @@ class Stat { */ protected $stats; - /** - * The value. - * - * @var array - */ - protected $value; - - /** - * Constructor. - */ - public function __construct() { - $this->value = $this->get_value(); - } - /** * Get the value. * - * @param array $index The index. This is an array of keys, which will be used to get the value. - * This will go over the array recursively, getting the value for the last key. - * See _wp_array_get for more info. + * @param string[]|int[] $index The index. This is an array of keys, + * which will be used to get the value. + * It will go over the array recursively, + * getting the value for the last key. + * See _wp_array_get for more info. * @return mixed */ - public function get_value( $index = [] ) { - if ( $this->value ) { - return $this->value; - } - + public function get_value( array $index = [] ) { if ( ! isset( $this->stats[ $this->type ] ) ) { $this->stats = \get_option( self::SETTING_NAME, [ $this->type => [] ] ); } @@ -76,12 +60,16 @@ public function get_value( $index = [] ) { /** * Set the value. * - * @param array $index The index. This is an array of keys, which will be used to set the value. - * This will go over the array recursively, updating the value for the last key. - * See _wp_array_set for more info. - * @param mixed $value The value. + * @param string[]|int[] $index The index. This is an array of keys, + * which will be used to set the value. + * It will go over the array recursively, + * updating the value for the last key. + * See _wp_array_set for more info. + * @param mixed $value The value. + * + * @return bool */ - public function set_value( $index, $value ) { + public function set_value( array $index, $value ): bool { // Call $this->get_value, to populate $this->stats. $stats = \get_option( self::SETTING_NAME, [ $this->type => [] ] ); @@ -92,7 +80,9 @@ public function set_value( $index, $value ) { \_wp_array_set( $stats, $index, $value ); // Save the option. - \update_option( self::SETTING_NAME, $stats ); + $updated = \update_option( self::SETTING_NAME, $stats ); $this->stats = $stats; + + return $updated; } } diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 000000000..8f93d17fa --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,11 @@ +parameters: + level: 6 + paths: + - . + excludePaths: + - vendor + ignoreErrors: + - '#Constant PROGRESS_PLANNER_URL not found.#' + - '#Property [a-zA-Z0-9\\_]+::\$[a-zA-Z0-9\\_]+ type has no value type specified in iterable type array.#' + - '#Method [a-zA-Z0-9\\_\:\(\)]+ return type has no value type specified in iterable type array.#' + - '#Method [a-zA-Z0-9\\_\:\(\)]+ has parameter \$[a-zA-Z0-9\\_]+ with no value type specified in iterable type array.#' diff --git a/views/admin-page-debug.php b/views/admin-page-debug.php index 51513cb05..5e2c54654 100644 --- a/views/admin-page-debug.php +++ b/views/admin-page-debug.php @@ -13,5 +13,5 @@
-
get_value() ); ?>
+
get_value() ); ?>
diff --git a/views/admin-page-form-filters.php b/views/admin-page-form-filters.php index 1aa2c43d9..cc7bd724f 100644 --- a/views/admin-page-form-filters.php +++ b/views/admin-page-form-filters.php @@ -8,7 +8,7 @@ */ // Values for the graph filters. -$prpl_filters_intervals = [ +$prpl_filter_intervals = [ 'days' => __( 'Days', 'progress-planner' ), 'weeks' => __( 'Weeks', 'progress-planner' ), 'months' => __( 'Months', 'progress-planner' ), @@ -19,14 +19,14 @@

- +
diff --git a/views/admin-page-form-scan.php b/views/admin-page-form-scan.php index 07626d5ad..f3c2c3434 100644 --- a/views/admin-page-form-scan.php +++ b/views/admin-page-form-scan.php @@ -13,5 +13,5 @@ diff --git a/views/admin-page-posts-count-progress.php b/views/admin-page-posts-count-progress.php index a5c29a228..f96ab30ad 100644 --- a/views/admin-page-posts-count-progress.php +++ b/views/admin-page-posts-count-progress.php @@ -10,9 +10,9 @@ echo ''; ( new \ProgressPlanner\Charts\Posts() )->render( - $prpl_stats_posts->get_post_types_names(), + \ProgressPlanner\Admin\Page::get_params()['stats']->get_post_types_names(), 'count', - $prpl_filters_interval, - $prpl_filters_number, + \ProgressPlanner\Admin\Page::get_params()['filter_interval'], + \ProgressPlanner\Admin\Page::get_params()['filter_number'], 0 ); diff --git a/views/admin-page-words-count-progress.php b/views/admin-page-words-count-progress.php index a887f1721..2d6a13d88 100644 --- a/views/admin-page-words-count-progress.php +++ b/views/admin-page-words-count-progress.php @@ -10,9 +10,9 @@ echo ''; ( new \ProgressPlanner\Charts\Posts() )->render( - $prpl_stats_posts->get_post_types_names(), + \ProgressPlanner\Admin\Page::get_params()['stats']->get_post_types_names(), 'words', - $prpl_filters_interval, - $prpl_filters_number, + \ProgressPlanner\Admin\Page::get_params()['filter_interval'], + \ProgressPlanner\Admin\Page::get_params()['filter_number'], 0 ); diff --git a/views/admin-page.php b/views/admin-page.php index 10176c093..827cfea85 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -5,25 +5,11 @@ * @package ProgressPlanner */ -// Get the stats object. -$prpl_stats_posts = new ProgressPlanner\Stats\Stat_Posts(); - -// phpcs:ignore WordPress.Security.NonceVerification.Missing -$prpl_filters_interval = isset( $_POST['interval'] ) ? sanitize_key( $_POST['interval'] ) : 'weeks'; -// phpcs:ignore WordPress.Security.NonceVerification.Missing -$prpl_filters_number = isset( $_POST['number'] ) ? (int) $_POST['number'] : 10; - -// Check if we have a scan pending. -$prpl_scan_pending = false; -$prpl_scan_progress = 0; -if ( empty( $prpl_stats_posts->get_value() ) ) { - $prpl_scan_pending = true; -} ?>

- + From 71fb42464dafdbc630cd7abb1f9537bca86400e0 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 15 Feb 2024 12:26:47 +0200 Subject: [PATCH 049/490] CS fixes --- includes/admin/class-page.php | 2 ++ includes/goals/class-goal-recurring.php | 2 +- includes/stats/class-stat.php | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/includes/admin/class-page.php b/includes/admin/class-page.php index 6e33ea4fe..b7597859f 100644 --- a/includes/admin/class-page.php +++ b/includes/admin/class-page.php @@ -164,7 +164,9 @@ public static function get_params() { } return [ 'stats' => $stats, + // phpcs:ignore WordPress.Security.NonceVerification.Missing 'filter_interval' => isset( $_POST['interval'] ) ? sanitize_key( $_POST['interval'] ) : 'weeks', + // phpcs:ignore WordPress.Security.NonceVerification.Missing 'filter_number' => isset( $_POST['number'] ) ? (int) $_POST['number'] : 10, 'scan_pending' => empty( $stats->get_value() ), ]; diff --git a/includes/goals/class-goal-recurring.php b/includes/goals/class-goal-recurring.php index 869dceea7..a65c3ec46 100644 --- a/includes/goals/class-goal-recurring.php +++ b/includes/goals/class-goal-recurring.php @@ -74,7 +74,7 @@ public function get_occurences() { return $this->occurences; } - $date = new Date(); + $date = new Date(); $ranges = $date->get_periods( $this->start, $this->end, $this->frequency ); foreach ( $ranges as $range ) { diff --git a/includes/stats/class-stat.php b/includes/stats/class-stat.php index 252a156e1..ac4edcf90 100644 --- a/includes/stats/class-stat.php +++ b/includes/stats/class-stat.php @@ -80,7 +80,7 @@ public function set_value( array $index, $value ): bool { \_wp_array_set( $stats, $index, $value ); // Save the option. - $updated = \update_option( self::SETTING_NAME, $stats ); + $updated = \update_option( self::SETTING_NAME, $stats ); $this->stats = $stats; return $updated; From 9349fb7161dbd3fd578cf41426884f8355791944 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 15 Feb 2024 12:28:52 +0200 Subject: [PATCH 050/490] Fix error when stats are empty --- includes/class-goals.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/includes/class-goals.php b/includes/class-goals.php index d2bb8ec67..54c20c417 100644 --- a/includes/class-goals.php +++ b/includes/class-goals.php @@ -41,6 +41,13 @@ private function register_core_goals() { private function register_weekly_post_goal() { $stats = new Stat_Posts(); + $stats_value = $stats->get_value(); + + // Bail early if there are no stats. + if ( empty( $stats_value ) ) { + return; + } + new Goal_Recurring( new Goal_Posts( [ @@ -61,7 +68,7 @@ private function register_weekly_post_goal() { ] ), 'weekly', - array_keys( $stats->get_value() )[0], // Beginning of the stats. + array_keys( $stats_value )[0], // Beginning of the stats. gmdate( Date::FORMAT ) // Today. ); } From 637776b811192cbe06dd16c50e650954036fb14d Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 15 Feb 2024 13:03:20 +0200 Subject: [PATCH 051/490] Add streaks --- includes/class-base.php | 1 - .../{class-goals.php => class-streaks.php} | 50 ++++++++++++------- views/admin-page-streak.php | 16 ++++++ views/admin-page.php | 2 + 4 files changed, 49 insertions(+), 20 deletions(-) rename includes/{class-goals.php => class-streaks.php} (61%) create mode 100644 views/admin-page-streak.php diff --git a/includes/class-base.php b/includes/class-base.php index 08120cec7..6bed57846 100644 --- a/includes/class-base.php +++ b/includes/class-base.php @@ -46,7 +46,6 @@ private function __construct() { $this->admin = new Admin(); new Stats(); - new Goals(); } /** diff --git a/includes/class-goals.php b/includes/class-streaks.php similarity index 61% rename from includes/class-goals.php rename to includes/class-streaks.php index 54c20c417..c3c1fadff 100644 --- a/includes/class-goals.php +++ b/includes/class-streaks.php @@ -1,36 +1,48 @@ register_core_goals(); - } +class Streaks { /** - * Register the goals. + * Get the streak for weekly posts. * - * @return void + * @return int The number of weeks for this streak. */ - private function register_core_goals() { - $this->register_weekly_post_goal(); + public function get_weekly_post_streak() { + $goal = $this->get_weekly_post_goal(); + + // Bail early if there is no goal. + if ( ! $goal ) { + return 0; + } + + // Reverse the order of the occurences. + $occurences = array_reverse( $goal->get_occurences() ); + $streak_nr = 0; + + foreach ( $occurences as $occurence ) { + // If the goal was not met, break the streak. + if ( ! $occurence->evaluate() ) { + break; + } + + ++$streak_nr; + } + + return $streak_nr; } /** @@ -38,7 +50,7 @@ private function register_core_goals() { * * @return void */ - private function register_weekly_post_goal() { + private function get_weekly_post_goal() { $stats = new Stat_Posts(); $stats_value = $stats->get_value(); @@ -48,7 +60,7 @@ private function register_weekly_post_goal() { return; } - new Goal_Recurring( + return new Goal_Recurring( new Goal_Posts( [ 'id' => 'weekly_post', diff --git a/views/admin-page-streak.php b/views/admin-page-streak.php new file mode 100644 index 000000000..eadd2a3f6 --- /dev/null +++ b/views/admin-page-streak.php @@ -0,0 +1,16 @@ +get_weekly_post_streak(); +$prpl_streak_color = 'hsl(' . min( 100, $prpl_streak_nr * 10 ) . ', 100%, 40%)'; +?> +
+

+

+ +

+
diff --git a/views/admin-page.php b/views/admin-page.php index 827cfea85..414169826 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -14,6 +14,8 @@
+ +
From 7b2cb02aef4c391e64c8d0af42dec47eda31f949 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 16 Feb 2024 10:17:39 +0200 Subject: [PATCH 052/490] minor tweak in views --- includes/charts/class-posts.php | 1 + views/admin-page-posts-count-progress.php | 3 +++ views/admin-page-words-count-progress.php | 2 ++ views/admin-page.php | 8 ++------ 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/includes/charts/class-posts.php b/includes/charts/class-posts.php index bd3beb41a..d77cc49dc 100644 --- a/includes/charts/class-posts.php +++ b/includes/charts/class-posts.php @@ -46,6 +46,7 @@ public function render( $post_types = [], $context = 'count', $interval = 'weeks $datasets[ $post_type ] = [ 'label' => \get_post_type_object( $post_type )->label, 'data' => [], + 'fill' => true, ]; } diff --git a/views/admin-page-posts-count-progress.php b/views/admin-page-posts-count-progress.php index f96ab30ad..9ae5d804f 100644 --- a/views/admin-page-posts-count-progress.php +++ b/views/admin-page-posts-count-progress.php @@ -5,6 +5,7 @@ * @package ProgressPlanner */ +echo '
'; echo '

'; esc_html_e( 'Posts count progress', 'progress-planner' ); echo '

'; @@ -16,3 +17,5 @@ \ProgressPlanner\Admin\Page::get_params()['filter_number'], 0 ); + +echo '
'; diff --git a/views/admin-page-words-count-progress.php b/views/admin-page-words-count-progress.php index 2d6a13d88..2fad846f3 100644 --- a/views/admin-page-words-count-progress.php +++ b/views/admin-page-words-count-progress.php @@ -5,6 +5,7 @@ * @package ProgressPlanner */ +echo '
'; echo '

'; esc_html_e( 'Words count progress', 'progress-planner' ); echo '

'; @@ -16,3 +17,4 @@ \ProgressPlanner\Admin\Page::get_params()['filter_number'], 0 ); +echo '
'; diff --git a/views/admin-page.php b/views/admin-page.php index 414169826..75e9987dd 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -16,12 +16,8 @@

-
- -
-
- -
+ +

From ffa1d85e594d4ae2934c31ef96423e9492adfd1c Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 16 Feb 2024 11:26:57 +0200 Subject: [PATCH 053/490] Allow multiple streaks goals & fix the related view --- includes/class-streaks.php | 117 ++++++++++++++++++++++-- includes/goals/class-goal-recurring.php | 9 ++ views/admin-page-streak.php | 23 +++-- 3 files changed, 135 insertions(+), 14 deletions(-) diff --git a/includes/class-streaks.php b/includes/class-streaks.php index c3c1fadff..e2c9a4185 100644 --- a/includes/class-streaks.php +++ b/includes/class-streaks.php @@ -16,17 +16,70 @@ */ class Streaks { + /** + * An array of recurring goals. + * + * @var Goal_Recurring[] + */ + private $recurring_goals = []; + + /** + * An instance of this class. + * + * @var \ProgressPlanner\Streaks + */ + private static $instance; + + /** + * Get the single instance of this class. + * + * @return \ProgressPlanner\Streaks + */ + public static function get_instance() { + if ( null === self::$instance ) { + self::$instance = new self(); + } + + return self::$instance; + } + + /** + * Constructor. + */ + private function __construct() { + $this->register_recurring_goals(); + } + + /** + * Register recurring goals. + * + * @return void + */ + private function register_recurring_goals() { + $this->recurring_goals['weekly_post'] = $this->get_weekly_post_goal(); + $this->recurring_goals['weekly_words'] = $this->get_weekly_words_goal(); + } + /** * Get the streak for weekly posts. * + * @param string $goal_id The goal ID. + * @param int $target The target number of weeks. + * Affects the color of the streak. + * * @return int The number of weeks for this streak. */ - public function get_weekly_post_streak() { - $goal = $this->get_weekly_post_goal(); + public function get_streak( $goal_id, $target ) { + $goal = $this->recurring_goals[ $goal_id ]; // Bail early if there is no goal. if ( ! $goal ) { - return 0; + return [ + 'number' => 0, + 'color' => 'hsl(0, 100%, 40%)', + 'title' => $goal->get_goal()->get_details()['title'], + 'description' => $goal->get_goal()->get_details()['description'], + ]; } // Reverse the order of the occurences. @@ -42,7 +95,12 @@ public function get_weekly_post_streak() { ++$streak_nr; } - return $streak_nr; + return [ + 'number' => $streak_nr, + 'color' => 'hsl(' . (int) min( 100, $streak_nr * 100 / $target ) . ', 100%, 40%)', + 'title' => $goal->get_goal()->get_details()['title'], + 'description' => $goal->get_goal()->get_details()['description'], + ]; } /** @@ -65,15 +123,15 @@ private function get_weekly_post_goal() { [ 'id' => 'weekly_post', 'title' => \esc_html__( 'Write a weekly blog post', 'progress-planner' ), - 'description' => '', + 'description' => \esc_html__( 'Streak: The number of weeks this goal has been accomplished consistently.', 'progress-planner' ), 'status' => 'active', - 'priority' => 'high', + 'priority' => 'low', 'evaluate' => function ( $goal_object ) use ( $stats ) { return (bool) count( $stats->get_stats( $goal_object->get_details()['start_date'], $goal_object->get_details()['end_date'], - [ 'post' ] + [] ) ); }, @@ -84,4 +142,49 @@ private function get_weekly_post_goal() { gmdate( Date::FORMAT ) // Today. ); } + + /** + * Register a weekly-words goal. + * + * @return void + */ + private function get_weekly_words_goal() { + $stats = new Stat_Posts(); + + $stats_value = $stats->get_value(); + + // Bail early if there are no stats. + if ( empty( $stats_value ) ) { + return; + } + + return new Goal_Recurring( + new Goal_Posts( + [ + 'id' => 'weekly_words', + 'title' => \esc_html__( 'Write 500 words/week', 'progress-planner' ), + 'description' => \esc_html__( 'Streak: The number of weeks this goal has been accomplished consistently.', 'progress-planner' ), + 'status' => 'active', + 'priority' => 'low', + 'evaluate' => function ( $goal_object ) use ( $stats ) { + $words = 0; + $posts = $stats->get_stats( + $goal_object->get_details()['start_date'], + $goal_object->get_details()['end_date'], + [ 'post' ] + ); + foreach ( $posts as $post_dates ) { + foreach ( $post_dates as $post_details ) { + $words += $post_details['words']; + } + } + return $words >= 500; + }, + ] + ), + 'weekly', + array_keys( $stats_value )[0], // Beginning of the stats. + gmdate( Date::FORMAT ) // Today. + ); + } } diff --git a/includes/goals/class-goal-recurring.php b/includes/goals/class-goal-recurring.php index a65c3ec46..6a155093e 100644 --- a/includes/goals/class-goal-recurring.php +++ b/includes/goals/class-goal-recurring.php @@ -64,6 +64,15 @@ public function __construct( $goal, $frequency, $start, $end ) { $this->end = $end; } + /** + * Get the goal title. + * + * @return string + */ + public function get_goal() { + return $this->goal; + } + /** * Build an array of occurences for the goal. * diff --git a/views/admin-page-streak.php b/views/admin-page-streak.php index eadd2a3f6..de4d445af 100644 --- a/views/admin-page-streak.php +++ b/views/admin-page-streak.php @@ -5,12 +5,21 @@ * @package ProgressPlanner */ -$prpl_streak_nr = ( new \ProgressPlanner\Streaks() )->get_weekly_post_streak(); -$prpl_streak_color = 'hsl(' . min( 100, $prpl_streak_nr * 10 ) . ', 100%, 40%)'; +$prpl_streaks = [ + 'weekly_post' => 10, // Number of posts per week, targetting for 10 weeks. + 'weekly_words' => 10, // Number of words per week, targetting for 10 weeks. +]; ?> -
-

-

- -

+ +
+ $prpl_streak_goal ) : ?> +
+ get_streak( $prpl_streak_id, $prpl_streak_goal ); ?> +

+

+

+ +

+
+
From c2aa2afe0f2ae6821cf8bfe4d6e92b38da8384a3 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 16 Feb 2024 11:29:32 +0200 Subject: [PATCH 054/490] rearrange views a bit --- views/admin-page.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/views/admin-page.php b/views/admin-page.php index 75e9987dd..b1cd7264b 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -12,10 +12,10 @@ - -

+ +

From 48b88f39d4f483667ac259d03ab26d33430ee4ff Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 19 Feb 2024 10:26:58 +0200 Subject: [PATCH 055/490] Add dashboard widget --- includes/admin/class-dashboard-widget.php | 48 +++++++++++++++++++++++ includes/class-admin.php | 2 + 2 files changed, 50 insertions(+) create mode 100644 includes/admin/class-dashboard-widget.php diff --git a/includes/admin/class-dashboard-widget.php b/includes/admin/class-dashboard-widget.php new file mode 100644 index 000000000..d2b9fe6e0 --- /dev/null +++ b/includes/admin/class-dashboard-widget.php @@ -0,0 +1,48 @@ + +
+ + + + + + +
+ admin_page = new Admin\Page(); + + new Admin\Dashboard_Widget(); } /** From 47239359cc927e428dadaf0e3ff0428b1febd087 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 19 Feb 2024 10:56:52 +0200 Subject: [PATCH 056/490] Some fixes for the admin dashboard --- includes/admin/class-dashboard-widget.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/includes/admin/class-dashboard-widget.php b/includes/admin/class-dashboard-widget.php index d2b9fe6e0..e8cc7ee87 100644 --- a/includes/admin/class-dashboard-widget.php +++ b/includes/admin/class-dashboard-widget.php @@ -37,10 +37,21 @@ public function render_dashboard_widget() { ?>
- +

+ ' . esc_html__( 'the Progress Planner admin page', 'progress-planner' ) . '' + ) + ?> +

+ + +
Date: Wed, 21 Feb 2024 12:49:59 +0200 Subject: [PATCH 057/490] refactor posts scanning --- includes/admin/class-page.php | 18 +- includes/class-stats.php | 11 +- .../stats/class-stat-posts-prepopulate.php | 166 ++++++++++-------- includes/stats/class-stat-posts.php | 69 ++++---- includes/stats/class-stat.php | 88 ---------- 5 files changed, 147 insertions(+), 205 deletions(-) delete mode 100644 includes/stats/class-stat.php diff --git a/includes/admin/class-page.php b/includes/admin/class-page.php index b7597859f..08fa718e2 100644 --- a/includes/admin/class-page.php +++ b/includes/admin/class-page.php @@ -110,19 +110,19 @@ public function ajax_scan() { // Scan the posts. $prepopulate = new \ProgressPlanner\Stats\Stat_Posts_Prepopulate(); - $prepopulate->prepopulate(); + $prepopulate->update_stats(); - // Get the last scanned post ID. - $last_scanned_id = $prepopulate->get_last_prepopulated_post(); + // Get the last scanned page. + $last_scanned_page = $prepopulate->get_last_scanned_page(); // Get the last post-ID that exists on the site. - $last_post_id = $prepopulate->get_last_post_id(); + $total_pages_to_scan = $prepopulate->get_total_pages_to_scan(); \wp_send_json_success( [ - 'lastScanned' => $last_scanned_id, - 'lastPost' => $last_post_id, - 'progress' => round( ( $last_scanned_id / $last_post_id ) * 100 ), + 'lastScanned' => $last_scanned_page, + 'lastPost' => $total_pages_to_scan, + 'progress' => round( ( $last_scanned_page / $total_pages_to_scan ) * 100 ), 'messages' => [ 'scanComplete' => \esc_html__( 'Scan complete.', 'progress-planner' ), ], @@ -142,8 +142,8 @@ public function ajax_reset_stats() { } // Reset the stats. - $stats = new \ProgressPlanner\Stats\Stat_Posts(); - $stats->reset_stats(); + \delete_option( static::SETTING_NAME ); + \delete_option( static::LAST_SCANNED_PAGE_OPTION ); \wp_send_json_success( [ diff --git a/includes/class-stats.php b/includes/class-stats.php index 52c8b87c9..d08c22842 100644 --- a/includes/class-stats.php +++ b/includes/class-stats.php @@ -7,13 +7,12 @@ namespace ProgressPlanner; -use ProgressPlanner\Stats\Stat; use ProgressPlanner\Stats\Stat_Posts; /** * Stats class. * - * This is a collection of individual Stat objects. + * This is a collection of objects. */ class Stats { @@ -35,11 +34,11 @@ public function __construct() { * Add a stat to the collection. * * @param string $id The ID of the stat. - * @param Stat $stat The stat object. + * @param Object $stat The stat object. * * @return void */ - public function add_stat( $id, Stat $stat ) { + public function add_stat( $id, $stat ) { $this->stats[ $id ] = $stat; } @@ -57,9 +56,9 @@ public function get_all_stats() { * * @param string $id The ID of the stat. * - * @return Stat + * @return Object */ - public function get_stat( $id ): Stat { + public function get_stat( $id ) { return $this->stats[ $id ]; } diff --git a/includes/stats/class-stat-posts-prepopulate.php b/includes/stats/class-stat-posts-prepopulate.php index 6b35c4c6c..52a3a521d 100644 --- a/includes/stats/class-stat-posts-prepopulate.php +++ b/includes/stats/class-stat-posts-prepopulate.php @@ -7,6 +7,8 @@ namespace ProgressPlanner\Stats; +use ProgressPlanner\Date; + /** * Prepopulate the posts stats. */ @@ -17,112 +19,134 @@ class Stat_Posts_Prepopulate extends Stat_Posts { * * @var int */ - const POSTS_PER_PAGE = 100; + const POSTS_PER_PAGE = 20; /** - * The last post-ID. + * The option used to store the last scanned page. * - * @var int + * @var string */ - private $last_post_id = 0; + const LAST_SCANNED_PAGE_OPTION = 'progress_planner_stats_last_scanned_page'; /** - * The last scanned post-ID. + * The total posts count. * * @var int */ - private $last_scanned_post_id = 0; + private static $posts_count = 0; /** - * Get the last page that was prepopulated from the API. + * Update stats for posts. + * - Gets the next page to scan. + * - Gets the posts for the page. + * - Updates the stats for the posts. + * - Updates the last scanned page option. * - * @return int + * @return void */ - public function get_last_prepopulated_post() { - // If we have the last scanned post, return it. - if ( $this->last_scanned_post_id ) { - return $this->last_scanned_post_id; - } + public function update_stats() { + $last_page = $this->get_last_scanned_page(); + $next_page = $last_page + 1; + $this->update_stats_for_posts( $next_page ); + $this->update_last_scanned_page( $next_page ); + } - // Try to get the value from the transient. - $cached = \get_transient( 'progress_planner_last_prepopulated_post' ); - if ( $cached ) { - $this->last_scanned_post_id = $cached; - return $this->last_scanned_post_id; + /** + * Update stats for posts. + * + * @param int $page The page to query. + */ + private function update_stats_for_posts( $page ) { + $posts = \get_posts( + [ + 'posts_per_page' => static::POSTS_PER_PAGE, + 'paged' => $page, + 'post_type' => $this->get_post_types_names(), + 'post_status' => 'publish', + ] + ); + + if ( ! $posts ) { + return; } - // Get the last scanned post-ID from the stats. - $option_value = $this->get_value(); - foreach ( $option_value as $posts ) { - foreach ( $posts as $post_id => $details ) { - if ( $post_id > $this->last_scanned_post_id ) { - $this->last_scanned_post_id = $post_id; - } + // Get the value from the option. + $value = \get_option( static::SETTING_NAME, [] ); + + // Loop through the posts and update the $value stats. + foreach ( $posts as $post ) { + // Get the date from the post, and convert it to the format we use. + $date = (int) mysql2date( Date::FORMAT, $post->post_date ); + + // If the date is not set in the option, set it to an empty array. + if ( ! isset( $value[ $date ] ) ) { + $value[ $date ] = []; } + + // Add the post to the date. + $value[ $date ][ $post->ID ] = [ + 'post_type' => $post->post_type, + 'words' => $this->get_word_count( $post->post_content ), + ]; } - return $this->last_scanned_post_id; + + // Save the option. + \update_option( static::SETTING_NAME, $value ); } /** - * Set the last prepopulated post. + * Get the total posts count. * - * @return void + * @return int */ - public function save_last_prepopulated_post() { - \set_transient( 'progress_planner_last_prepopulated_post', $this->last_scanned_post_id, \HOUR_IN_SECONDS ); + private function get_posts_count() { + if ( static::$posts_count ) { + return static::$posts_count; + } + foreach ( $this->get_post_types_names() as $post_type ) { + static::$posts_count += \wp_count_posts( $post_type )->publish; + } + return static::$posts_count; } /** - * Get posts and prepopulate the stats. + * Get number of pages to scan. * - * @return void + * @return int */ - public function prepopulate() { - // Get the last post we processed. - $last_id = $this->get_last_prepopulated_post(); - - // Build an array of posts to save. - $post_ids = \range( $last_id, $last_id + self::POSTS_PER_PAGE ); - - foreach ( $post_ids as $post_id ) { - $post = get_post( $post_id ); + public function get_total_pages_to_scan() { + return \ceil( $this->get_posts_count() / static::POSTS_PER_PAGE ); + } - // If the post doesn't exist or is not publish, skip it. - if ( ! $post || 'publish' !== $post->post_status ) { - $this->last_scanned_post_id = $post_id; - $this->save_last_prepopulated_post(); - continue; - } + /** + * Get last scanned page. + * + * @return int + */ + public function get_last_scanned_page() { + return (int) \get_option( static::LAST_SCANNED_PAGE_OPTION, 1 ); + } - $this->save_post( $post ); - $this->last_scanned_post_id = $post->ID; - $this->save_last_prepopulated_post(); + /** + * Update last scanned page. + * + * @param int $page The page to set. + */ + private function update_last_scanned_page( $page ) { + if ( $page > $this->get_total_pages_to_scan() ) { + \delete_option( static::LAST_SCANNED_PAGE_OPTION ); + return; } + \update_option( static::LAST_SCANNED_PAGE_OPTION, $page ); } /** - * Get the last post-ID created. + * Reset the stats in our database. * - * @return int + * @return void */ - public function get_last_post_id() { - if ( $this->last_post_id ) { - return $this->last_post_id; - } - $last_post = \get_posts( - [ - 'posts_per_page' => 1, - 'post_type' => $this->get_post_types_names(), - 'post_status' => 'publish', - 'suppress_filters' => false, - 'order' => 'DESC', - 'orderby' => 'ID', - ] - ); - if ( empty( $last_post ) ) { - return 0; - } - $this->last_post_id = $last_post[0]->ID; - return $this->last_post_id; + public function reset_stats() { + \delete_option( static::SETTING_NAME ); + \delete_option( static::LAST_SCANNED_PAGE_OPTION ); } } diff --git a/includes/stats/class-stat-posts.php b/includes/stats/class-stat-posts.php index aff5a39c3..02c6d367f 100644 --- a/includes/stats/class-stat-posts.php +++ b/includes/stats/class-stat-posts.php @@ -12,25 +12,20 @@ /** * Stats about posts. */ -class Stat_Posts extends Stat { +class Stat_Posts { /** - * The stat type. This is used as a key in the settings array. - * - * @var string + * The setting name. */ - protected $type = 'posts'; + const SETTING_NAME = 'progress_planner_stats_posts'; /** * Get the value. * - * @param string[]|int[] $index The index. This is an array of keys, which will be used to get the value. - * This will go over the array recursively, getting the value for the last key. - * See _wp_array_get for more info. * @return mixed */ - public function get_value( $index = [] ) { - $value = parent::get_value( $index ); + public function get_value() { + $value = \get_option( static::SETTING_NAME, [] ); ksort( $value ); return $value; } @@ -40,20 +35,20 @@ public function get_value( $index = [] ) { * * @param \WP_Post $post The post. * - * @return void + * @return bool */ protected function save_post( $post ) { - // Get the date. - $date = (int) mysql2date( Date::FORMAT, $post->post_date ); - - // Add the post to the stats. - $this->set_value( - [ $date, $post->ID ], - [ - 'post_type' => $post->post_type, - 'words' => \str_word_count( $post->post_content ), - ], - ); + $value = \get_option( static::SETTING_NAME, [] ); + $date = (int) mysql2date( Date::FORMAT, $post->post_date ); + + if ( ! isset( $value[ $date ] ) ) { + $value[ $date ] = []; + } + $value[ $date ][ $post->ID ] = [ + 'post_type' => $post->post_type, + 'words' => $this->get_word_count( $post->post_content ), + ]; + return \update_option( static::SETTING_NAME, $value ); } /** @@ -95,15 +90,6 @@ public function get_stats( $start_date, $end_date, $post_types = [] ) { return $stats; } - /** - * Reset the stats in our database. - * - * @return void - */ - public function reset_stats() { - $this->set_value( [], [] ); - } - /** * Get an array of post-types names for the stats. * @@ -115,4 +101,25 @@ public function get_post_types_names() { return array_keys( $post_types ); } + + /** + * Get words count from content. + * + * This method will render shortcodes, blocks, + * and strip HTML before counting the words. + * + * @param string $content The content. + * + * @return int + */ + protected function get_word_count( $content ) { + // Parse blocks and shortcodes. + $content = \do_blocks( \do_shortcode( $content ) ); + + // Strip HTML. + $content = \wp_strip_all_tags( $content, true ); + + // Count words. + return \str_word_count( $content ); + } } diff --git a/includes/stats/class-stat.php b/includes/stats/class-stat.php deleted file mode 100644 index ac4edcf90..000000000 --- a/includes/stats/class-stat.php +++ /dev/null @@ -1,88 +0,0 @@ -stats[ $this->type ] ) ) { - $this->stats = \get_option( self::SETTING_NAME, [ $this->type => [] ] ); - } - - if ( ! empty( $index ) ) { - return \_wp_array_get( $this->stats[ $this->type ], $index ); - } - - return $this->stats[ $this->type ]; - } - - /** - * Set the value. - * - * @param string[]|int[] $index The index. This is an array of keys, - * which will be used to set the value. - * It will go over the array recursively, - * updating the value for the last key. - * See _wp_array_set for more info. - * @param mixed $value The value. - * - * @return bool - */ - public function set_value( array $index, $value ): bool { - // Call $this->get_value, to populate $this->stats. - $stats = \get_option( self::SETTING_NAME, [ $this->type => [] ] ); - - // Add $this->type to the beginning of the index array. - \array_unshift( $index, $this->type ); - - // Update the value in the array. - \_wp_array_set( $stats, $index, $value ); - - // Save the option. - $updated = \update_option( self::SETTING_NAME, $stats ); - $this->stats = $stats; - - return $updated; - } -} From 036084c0bb2a929a133fcbbc34290fa53cd1f608 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 21 Feb 2024 12:50:07 +0200 Subject: [PATCH 058/490] CS --- includes/admin/class-dashboard-widget.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/admin/class-dashboard-widget.php b/includes/admin/class-dashboard-widget.php index e8cc7ee87..ccdc9fc95 100644 --- a/includes/admin/class-dashboard-widget.php +++ b/includes/admin/class-dashboard-widget.php @@ -16,7 +16,7 @@ class Dashboard_Widget { * Constructor. */ public function __construct() { - \add_action( 'wp_dashboard_setup', array( $this, 'add_dashboard_widget' ) ); + \add_action( 'wp_dashboard_setup', [ $this, 'add_dashboard_widget' ] ); } /** From d111dc3d4a6957d1623b908fdde9464bf3d48621 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 21 Feb 2024 12:50:46 +0200 Subject: [PATCH 059/490] JS fix --- assets/js/admin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/js/admin.js b/assets/js/admin.js index 20b5ee75a..8de488f9f 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -143,6 +143,7 @@ progressPlannerDomReady( () => { resetForm.addEventListener( 'submit', ( e ) => { e.preventDefault(); resetForm.querySelector( 'input[type="submit"]' ).disabled = true; + resetForm.querySelector( 'input[type="submit"]' ).value = progressPlanner.l10n.resettingStats; // Make an AJAX request to reset the stats. progressPlannerAjaxRequest( { @@ -152,7 +153,6 @@ progressPlannerDomReady( () => { _ajax_nonce: progressPlanner.nonce, }, successAction: ( response ) => { - resetForm.querySelector( 'input[type="submit"]' ).value = progressPlanner.l10n.resettingStats; // Refresh the page. location.reload(); }, From 3ab9fc116df89ecdfafa3472f92c4d76a2c7942c Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 21 Feb 2024 14:34:33 +0200 Subject: [PATCH 060/490] Simplify structure for posts stats & add hook on post-save --- assets/js/admin.js | 2 +- includes/admin/class-page.php | 20 +- .../stats/class-stat-posts-prepopulate.php | 152 --------------- includes/stats/class-stat-posts.php | 181 ++++++++++++++++-- 4 files changed, 175 insertions(+), 180 deletions(-) delete mode 100644 includes/stats/class-stat-posts-prepopulate.php diff --git a/assets/js/admin.js b/assets/js/admin.js index 8de488f9f..9fb5cf69d 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -60,7 +60,7 @@ const progressPlannerTriggerScan = () => { progressBar.value = response.data.progress; } - console.info( `Progress: ${response.data.progress}%, (${response.data.lastScanned}/${response.data.lastPost})` ); + console.info( `Progress: ${response.data.progress}%, (${response.data.lastScanned}/${response.data.lastPage})` ); // Refresh the page when scan has finished. if ( response.data.progress >= 100 ) { diff --git a/includes/admin/class-page.php b/includes/admin/class-page.php index 08fa718e2..2688c007e 100644 --- a/includes/admin/class-page.php +++ b/includes/admin/class-page.php @@ -109,20 +109,14 @@ public function ajax_scan() { } // Scan the posts. - $prepopulate = new \ProgressPlanner\Stats\Stat_Posts_Prepopulate(); - $prepopulate->update_stats(); - - // Get the last scanned page. - $last_scanned_page = $prepopulate->get_last_scanned_page(); - - // Get the last post-ID that exists on the site. - $total_pages_to_scan = $prepopulate->get_total_pages_to_scan(); + $posts_stats = new \ProgressPlanner\Stats\Stat_Posts(); + $updated_stats = $posts_stats->update_stats(); \wp_send_json_success( [ - 'lastScanned' => $last_scanned_page, - 'lastPost' => $total_pages_to_scan, - 'progress' => round( ( $last_scanned_page / $total_pages_to_scan ) * 100 ), + 'lastScanned' => $updated_stats['lastScannedPage'], + 'lastPage' => $updated_stats['lastPage'], + 'progress' => $updated_stats['progress'], 'messages' => [ 'scanComplete' => \esc_html__( 'Scan complete.', 'progress-planner' ), ], @@ -142,8 +136,8 @@ public function ajax_reset_stats() { } // Reset the stats. - \delete_option( static::SETTING_NAME ); - \delete_option( static::LAST_SCANNED_PAGE_OPTION ); + $posts_stats = new \ProgressPlanner\Stats\Stat_Posts(); + $posts_stats->reset_stats(); \wp_send_json_success( [ diff --git a/includes/stats/class-stat-posts-prepopulate.php b/includes/stats/class-stat-posts-prepopulate.php deleted file mode 100644 index 52a3a521d..000000000 --- a/includes/stats/class-stat-posts-prepopulate.php +++ /dev/null @@ -1,152 +0,0 @@ -get_last_scanned_page(); - $next_page = $last_page + 1; - $this->update_stats_for_posts( $next_page ); - $this->update_last_scanned_page( $next_page ); - } - - /** - * Update stats for posts. - * - * @param int $page The page to query. - */ - private function update_stats_for_posts( $page ) { - $posts = \get_posts( - [ - 'posts_per_page' => static::POSTS_PER_PAGE, - 'paged' => $page, - 'post_type' => $this->get_post_types_names(), - 'post_status' => 'publish', - ] - ); - - if ( ! $posts ) { - return; - } - - // Get the value from the option. - $value = \get_option( static::SETTING_NAME, [] ); - - // Loop through the posts and update the $value stats. - foreach ( $posts as $post ) { - // Get the date from the post, and convert it to the format we use. - $date = (int) mysql2date( Date::FORMAT, $post->post_date ); - - // If the date is not set in the option, set it to an empty array. - if ( ! isset( $value[ $date ] ) ) { - $value[ $date ] = []; - } - - // Add the post to the date. - $value[ $date ][ $post->ID ] = [ - 'post_type' => $post->post_type, - 'words' => $this->get_word_count( $post->post_content ), - ]; - } - - // Save the option. - \update_option( static::SETTING_NAME, $value ); - } - - /** - * Get the total posts count. - * - * @return int - */ - private function get_posts_count() { - if ( static::$posts_count ) { - return static::$posts_count; - } - foreach ( $this->get_post_types_names() as $post_type ) { - static::$posts_count += \wp_count_posts( $post_type )->publish; - } - return static::$posts_count; - } - - /** - * Get number of pages to scan. - * - * @return int - */ - public function get_total_pages_to_scan() { - return \ceil( $this->get_posts_count() / static::POSTS_PER_PAGE ); - } - - /** - * Get last scanned page. - * - * @return int - */ - public function get_last_scanned_page() { - return (int) \get_option( static::LAST_SCANNED_PAGE_OPTION, 1 ); - } - - /** - * Update last scanned page. - * - * @param int $page The page to set. - */ - private function update_last_scanned_page( $page ) { - if ( $page > $this->get_total_pages_to_scan() ) { - \delete_option( static::LAST_SCANNED_PAGE_OPTION ); - return; - } - \update_option( static::LAST_SCANNED_PAGE_OPTION, $page ); - } - - /** - * Reset the stats in our database. - * - * @return void - */ - public function reset_stats() { - \delete_option( static::SETTING_NAME ); - \delete_option( static::LAST_SCANNED_PAGE_OPTION ); - } -} diff --git a/includes/stats/class-stat-posts.php b/includes/stats/class-stat-posts.php index 02c6d367f..7a6d7812e 100644 --- a/includes/stats/class-stat-posts.php +++ b/includes/stats/class-stat-posts.php @@ -16,18 +16,81 @@ class Stat_Posts { /** * The setting name. + * + * @var string */ const SETTING_NAME = 'progress_planner_stats_posts'; + /** + * The number of posts to scan at a time. + * + * @var int + */ + const SCAN_POSTS_PER_PAGE = 20; + + /** + * The option used to store the last scanned page. + * + * @var string + */ + const LAST_SCANNED_PAGE_OPTION = 'progress_planner_stats_last_scanned_page'; + + /** + * The stats. Used for caching purposes. + * + * @var array + */ + private static $stats; + + /** + * Constructor. + */ + public function __construct() { + $this->register_hooks(); + } + + /** + * Register the hooks. + * + * @return void + */ + private function register_hooks() { + \add_action( 'save_post', [ $this, 'save_post' ], 10, 2 ); + } + + /** + * Run actions when saving a post. + * + * @param int $post_id The post ID. + * @param \WP_Post $post The post object. + */ + public function save_post( $post_id, $post ) { + // Bail if the post is not included in the post-types we're tracking. + $post_types = $this->get_post_types_names(); + if ( ! \in_array( $post->post_type, $post_types, true ) ) { + return; + } + + // Bail if the post is not published. + if ( 'publish' !== $post->post_status ) { + return; + } + + $this->save_post_stats( $post ); + } + /** * Get the value. * * @return mixed */ public function get_value() { - $value = \get_option( static::SETTING_NAME, [] ); - ksort( $value ); - return $value; + if ( ! self::$stats ) { + $value = \get_option( static::SETTING_NAME, [] ); + ksort( $value ); + self::$stats = $value; + } + return self::$stats; } /** @@ -37,10 +100,17 @@ public function get_value() { * * @return bool */ - protected function save_post( $post ) { + protected function save_post_stats( $post ) { $value = \get_option( static::SETTING_NAME, [] ); $date = (int) mysql2date( Date::FORMAT, $post->post_date ); + // Remove the post from stats if it's already stored in another date. + foreach ( $value as $date_key => $date_value ) { + if ( isset( $date_value[ $post->ID ] ) ) { + unset( $value[ $date_key ][ $post->ID ] ); + } + } + if ( ! isset( $value[ $date ] ) ) { $value[ $date ] = []; } @@ -64,10 +134,10 @@ public function get_stats( $start_date, $end_date, $post_types = [] ) { $stats = $this->get_value(); // Get the stats for the date range and post types. - foreach ( array_keys( $stats ) as $key ) { - // Remove the stats that are outside the date range. - if ( $key <= $start_date || $key > $end_date ) { - unset( $stats[ $key ] ); + foreach ( $stats as $date => $date_stats ) { + // Remove stats outside the date range. + if ( $date <= $start_date || $date > $end_date ) { + unset( $stats[ $date ] ); continue; } @@ -76,16 +146,19 @@ public function get_stats( $start_date, $end_date, $post_types = [] ) { continue; } - // Remove the stats that are not in the post types. - foreach ( $stats[ $key ] as $post_id => $details ) { + // Remove stats not in the post types. + foreach ( $stats[ $date ] as $post_id => $details ) { if ( ! \in_array( $details['post_type'], $post_types, true ) ) { - unset( $stats[ $key ][ $post_id ] ); + unset( $stats[ $date ][ $post_id ] ); } } - } - // Filter out empty dates. - $stats = \array_filter( $stats ); + // Remove empty dates. + if ( ! $stats[ $date ] || empty( $stats[ $date ] ) ) { + unset( $stats[ $date ] ); + continue; + } + } return $stats; } @@ -122,4 +195,84 @@ protected function get_word_count( $content ) { // Count words. return \str_word_count( $content ); } + + /** + * Update stats for posts. + * - Gets the next page to scan. + * - Gets the posts for the page. + * - Updates the stats for the posts. + * - Updates the last scanned page option. + * + * @return array + */ + public function update_stats() { + + // Get the total number of posts. + $total_posts_count = 0; + foreach ( $this->get_post_types_names() as $post_type ) { + $total_posts_count += \wp_count_posts( $post_type )->publish; + } + // Calculate the total pages to scan. + $total_pages = \ceil( $total_posts_count / static::SCAN_POSTS_PER_PAGE ); + // Get the last scanned page. + $last_page = (int) \get_option( static::LAST_SCANNED_PAGE_OPTION, 0 ); + // The current page to scan. + $current_page = $last_page + 1; + + // Get posts. + $posts = \get_posts( + [ + 'posts_per_page' => static::SCAN_POSTS_PER_PAGE, + 'paged' => $current_page, + 'post_type' => $this->get_post_types_names(), + 'post_status' => 'publish', + ] + ); + + if ( $posts ) { + // Get the value from the option. + $value = \get_option( static::SETTING_NAME, [] ); + + // Loop through the posts and update the $value stats. + foreach ( $posts as $post ) { + // Get the date from the post, and convert it to the format we use. + $date = (int) mysql2date( Date::FORMAT, $post->post_date ); + + // If the date is not set in the option, set it to an empty array. + if ( ! isset( $value[ $date ] ) ) { + $value[ $date ] = []; + } + + // Add the post to the date. + $value[ $date ][ $post->ID ] = [ + 'post_type' => $post->post_type, + 'words' => $this->get_word_count( $post->post_content ), + ]; + } + + // Save the option. + \update_option( static::SETTING_NAME, $value ); + } + + if ( $current_page > $total_pages ) { + \delete_option( static::LAST_SCANNED_PAGE_OPTION ); + } + \update_option( static::LAST_SCANNED_PAGE_OPTION, $current_page ); + + return [ + 'lastScannedPage' => $last_page, + 'lastPage' => $total_pages, + 'progress' => round( ( $current_page / max( 1, $total_pages ) ) * 100 ), + ]; + } + + /** + * Reset the stats in our database. + * + * @return void + */ + public function reset_stats() { + \delete_option( static::SETTING_NAME ); + \delete_option( static::LAST_SCANNED_PAGE_OPTION ); + } } From 79823a48ef22d425efd47a6243651c9524818ac0 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 21 Feb 2024 15:06:48 +0200 Subject: [PATCH 061/490] Update stats when changing and deleting posts --- includes/stats/class-stat-posts.php | 42 +++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/includes/stats/class-stat-posts.php b/includes/stats/class-stat-posts.php index 7a6d7812e..92006931a 100644 --- a/includes/stats/class-stat-posts.php +++ b/includes/stats/class-stat-posts.php @@ -56,6 +56,9 @@ public function __construct() { */ private function register_hooks() { \add_action( 'save_post', [ $this, 'save_post' ], 10, 2 ); + \add_action( 'wp_insert_post', [ $this, 'save_post' ], 10, 2 ); + \add_action( 'delete_post', [ $this, 'delete_post' ] ); + \add_action( 'transition_post_status', [ $this, 'transition_post_status' ], 10, 3 ); } /** @@ -79,6 +82,45 @@ public function save_post( $post_id, $post ) { $this->save_post_stats( $post ); } + /** + * Delete a post from stats. + * + * @param int $post_id The post ID. + */ + public function delete_post( $post_id ) { + $value = \get_option( static::SETTING_NAME, [] ); + $updated = false; + // Remove the post from stats if it's already stored in another date. + foreach ( $value as $date_key => $date_value ) { + if ( isset( $date_value[ $post_id ] ) ) { + unset( $value[ $date_key ][ $post_id ] ); + $updated = true; + } + } + + if ( $updated ) { + \update_option( static::SETTING_NAME, $value ); + } + } + + /** + * Run actions when transitioning a post status. + * + * @param string $new_status The new status. + * @param string $old_status The old status. + * @param \WP_Post $post The post object. + */ + public function transition_post_status( $new_status, $old_status, $post ) { + // Delete the post from stats. + if ( 'publish' === $old_status && 'publish' !== $new_status ) { + $this->delete_post( $post->ID ); + } + // Add the post to stats. + if ( 'publish' !== $old_status && 'publish' === $new_status ) { + $this->save_post_stats( $post ); + } + } + /** * Get the value. * From c5c98d39a41bf974179f324540c44d6f2a22b400 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 21 Feb 2024 15:06:59 +0200 Subject: [PATCH 062/490] Disable streaks for now --- views/admin-page-streak.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/views/admin-page-streak.php b/views/admin-page-streak.php index de4d445af..a7447b07c 100644 --- a/views/admin-page-streak.php +++ b/views/admin-page-streak.php @@ -5,6 +5,9 @@ * @package ProgressPlanner */ +// TODO: DISABLE THIS FOR NOW, IT'S NOT WORKING. +return; + $prpl_streaks = [ 'weekly_post' => 10, // Number of posts per week, targetting for 10 weeks. 'weekly_words' => 10, // Number of words per week, targetting for 10 weeks. From dd3c02f9007aa4adbbb44de6f2a0260232da367b Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 21 Feb 2024 15:43:03 +0200 Subject: [PATCH 063/490] Add offset to charts --- includes/charts/class-posts.php | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/includes/charts/class-posts.php b/includes/charts/class-posts.php index d77cc49dc..55d313cff 100644 --- a/includes/charts/class-posts.php +++ b/includes/charts/class-posts.php @@ -51,6 +51,21 @@ public function render( $post_types = [], $context = 'count', $interval = 'weeks } $stat_posts = new Stat_Posts(); + + // Calculate zero stats to be used as the baseline. + $zero_stats = $stat_posts->get_stats( + 19700101, + (int) gmdate( Date::FORMAT, strtotime( "-$range $interval" ) ), + $post_types + ); + foreach ( $zero_stats as $zero_posts ) { + foreach ( $zero_posts as $zero_post ) { + $post_type_count_totals[ $zero_post['post_type'] ] += 'words' === $context + ? $zero_post['words'] + : 1; + } + } + foreach ( $range_array as $start => $end ) { $stats = $stat_posts->get_stats( (int) gmdate( Date::FORMAT, strtotime( "-$start $interval" ) ), @@ -65,11 +80,9 @@ public function render( $post_types = [], $context = 'count', $interval = 'weeks foreach ( $stats as $posts ) { foreach ( $posts as $post_details ) { if ( $post_details['post_type'] === $post_type ) { - if ( 'words' === $context ) { - $post_type_count_totals[ $post_type ] += $post_details['words']; - continue; - } - ++$post_type_count_totals[ $post_type ]; + $post_type_count_totals[ $post_type ] += 'words' === $context + ? $post_details['words'] + : 1; } } } From e07d8559641f2970acc01fe76690427b9731a620 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 21 Feb 2024 15:55:02 +0200 Subject: [PATCH 064/490] Improve stats display --- includes/charts/class-posts.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/charts/class-posts.php b/includes/charts/class-posts.php index 55d313cff..ba6eae17e 100644 --- a/includes/charts/class-posts.php +++ b/includes/charts/class-posts.php @@ -44,9 +44,9 @@ public function render( $post_types = [], $context = 'count', $interval = 'weeks foreach ( $post_types as $post_type ) { $post_type_count_totals[ $post_type ] = 0; $datasets[ $post_type ] = [ - 'label' => \get_post_type_object( $post_type )->label, - 'data' => [], - 'fill' => true, + 'label' => \get_post_type_object( $post_type )->label, + 'data' => [], + 'tension' => 0.2, ]; } From 66e6c54a32b4db59cdc35f890c6b4a3ac4b2fbc0 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 22 Feb 2024 10:21:43 +0200 Subject: [PATCH 065/490] Add scrolling to debug data --- views/admin-page-debug.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/views/admin-page-debug.php b/views/admin-page-debug.php index 5e2c54654..6f9b5f70f 100644 --- a/views/admin-page-debug.php +++ b/views/admin-page-debug.php @@ -13,5 +13,10 @@
-
get_value() ); ?>
+
+		get_value() );
+		?>
+	
From 56075913f9830820cdab69fc7fe9cad7d1199da5 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 22 Feb 2024 10:30:02 +0200 Subject: [PATCH 066/490] Fix streaks implementation --- includes/class-date.php | 5 ++++- includes/class-streaks.php | 19 ++++++++++--------- includes/goals/class-goal-recurring.php | 8 ++++++++ views/admin-page-streak.php | 3 --- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/includes/class-date.php b/includes/class-date.php index 1b8d10892..c420d7a59 100644 --- a/includes/class-date.php +++ b/includes/class-date.php @@ -73,10 +73,13 @@ public function get_periods( $start, $end, $frequency ) { default: // Default to weekly. $interval = new \DateInterval( 'P1W' ); + // Make sure we start and end on a Monday. + $start->modify( 'last Monday' ); + $end->modify( 'next Monday' ); break; } - $period = new \DatePeriod( $start, $interval, 100 ); + $period = new \DatePeriod( $start, $interval, $end ); $dates_array = []; foreach ( $period as $date ) { $dates_array[] = $date->format( self::FORMAT ); diff --git a/includes/class-streaks.php b/includes/class-streaks.php index e2c9a4185..7632c2064 100644 --- a/includes/class-streaks.php +++ b/includes/class-streaks.php @@ -83,21 +83,22 @@ public function get_streak( $goal_id, $target ) { } // Reverse the order of the occurences. - $occurences = array_reverse( $goal->get_occurences() ); - $streak_nr = 0; + $occurences = $goal->get_occurences(); + // Calculate the streak number. + $streak_nr = 0; foreach ( $occurences as $occurence ) { - // If the goal was not met, break the streak. - if ( ! $occurence->evaluate() ) { - break; - } - - ++$streak_nr; + /** + * Evaluate the occurence. + * If the occurence is true, then increment the streak number. + * Otherwise, reset the streak number. + */ + $streak_nr = $occurence->evaluate() ? $streak_nr + 1 : 0; } return [ 'number' => $streak_nr, - 'color' => 'hsl(' . (int) min( 100, $streak_nr * 100 / $target ) . ', 100%, 40%)', + 'color' => 'hsl(' . (int) min( 100, $streak_nr * 200 / $target ) . ', 100%, 40%)', 'title' => $goal->get_goal()->get_details()['title'], 'description' => $goal->get_goal()->get_details()['description'], ]; diff --git a/includes/goals/class-goal-recurring.php b/includes/goals/class-goal-recurring.php index 6a155093e..8af6271ed 100644 --- a/includes/goals/class-goal-recurring.php +++ b/includes/goals/class-goal-recurring.php @@ -86,6 +86,14 @@ public function get_occurences() { $date = new Date(); $ranges = $date->get_periods( $this->start, $this->end, $this->frequency ); + // If the last range ends before today, add a new range. + if ( (int) gmdate( Date::FORMAT ) > (int) end( $ranges )['end'] ) { + $ranges[] = $date->get_range( + end( $ranges )['end'], + gmdate( Date::FORMAT, strtotime( '+1 day' ) ), + ); + } + foreach ( $ranges as $range ) { $goal = clone $this->goal; $goal->set_start_date( $range['start'] ); diff --git a/views/admin-page-streak.php b/views/admin-page-streak.php index a7447b07c..de4d445af 100644 --- a/views/admin-page-streak.php +++ b/views/admin-page-streak.php @@ -5,9 +5,6 @@ * @package ProgressPlanner */ -// TODO: DISABLE THIS FOR NOW, IT'S NOT WORKING. -return; - $prpl_streaks = [ 'weekly_post' => 10, // Number of posts per week, targetting for 10 weeks. 'weekly_words' => 10, // Number of words per week, targetting for 10 weeks. From 506350cecf9cee9667b9ebabfdea40b03bc340a6 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 22 Feb 2024 10:30:29 +0200 Subject: [PATCH 067/490] Style debug data --- views/admin-page-debug.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/admin-page-debug.php b/views/admin-page-debug.php index 6f9b5f70f..d3a3ae7c3 100644 --- a/views/admin-page-debug.php +++ b/views/admin-page-debug.php @@ -13,7 +13,7 @@
-
+	
 		get_value() );

From b5462b7330cfffb8368e0dbe6383f5d8e9cfc721 Mon Sep 17 00:00:00 2001
From: Ari Stathopoulos 
Date: Thu, 22 Feb 2024 10:33:36 +0200
Subject: [PATCH 068/490] partial revert fot streak color calculation

---
 includes/class-streaks.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/includes/class-streaks.php b/includes/class-streaks.php
index 7632c2064..0ff7a5430 100644
--- a/includes/class-streaks.php
+++ b/includes/class-streaks.php
@@ -98,7 +98,7 @@ public function get_streak( $goal_id, $target ) {
 
 		return [
 			'number'      => $streak_nr,
-			'color'       => 'hsl(' . (int) min( 100, $streak_nr * 200 / $target ) . ', 100%, 40%)',
+			'color'       => 'hsl(' . (int) min( 100, $streak_nr * 100 / $target ) . ', 100%, 40%)',
 			'title'       => $goal->get_goal()->get_details()['title'],
 			'description' => $goal->get_goal()->get_details()['description'],
 		];

From bcbb646239126735413693f21cf86664a4072b53 Mon Sep 17 00:00:00 2001
From: Ari Stathopoulos 
Date: Thu, 22 Feb 2024 10:51:19 +0200
Subject: [PATCH 069/490] Change max hue to 125

---
 includes/class-streaks.php | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/includes/class-streaks.php b/includes/class-streaks.php
index 0ff7a5430..689e75074 100644
--- a/includes/class-streaks.php
+++ b/includes/class-streaks.php
@@ -96,9 +96,12 @@ public function get_streak( $goal_id, $target ) {
 			$streak_nr = $occurence->evaluate() ? $streak_nr + 1 : 0;
 		}
 
+		// Calculate the hue for the color.
+		$hue = (int) min( 125, $streak_nr * 125 / $target );
+
 		return [
 			'number'      => $streak_nr,
-			'color'       => 'hsl(' . (int) min( 100, $streak_nr * 100 / $target ) . ', 100%, 40%)',
+			'color'       => "hsl($hue, 100%, 40%)",
 			'title'       => $goal->get_goal()->get_details()['title'],
 			'description' => $goal->get_goal()->get_details()['description'],
 		];

From cd1e3fcb6651eec45a5c632d40a3ac496ef78914 Mon Sep 17 00:00:00 2001
From: Ari Stathopoulos 
Date: Tue, 27 Feb 2024 11:04:09 +0200
Subject: [PATCH 070/490] Refactor for custom tables & activities framework

---
 includes/activities/class-activity-post.php | 271 +++++++++++++++
 includes/activities/class-activity.php      | 197 +++++++++++
 includes/activities/class-query.php         | 350 ++++++++++++++++++++
 includes/admin/class-page.php               |   6 +-
 includes/charts/class-posts.php             |  82 ++---
 includes/class-date.php                     |  56 ++--
 includes/class-stats.php                    |  16 +
 includes/class-streaks.php                  |  72 ++--
 includes/goals/class-goal-recurring.php     |   5 +-
 includes/scan/class-posts.php               | 120 +++++++
 includes/stats/class-stat-posts.php         | 298 +----------------
 progress-planner.php                        |   2 +
 views/admin-page-debug.php                  |   2 +-
 views/admin-page-posts-count-progress.php   |   2 +-
 views/admin-page-words-count-progress.php   |   2 +-
 15 files changed, 1059 insertions(+), 422 deletions(-)
 create mode 100644 includes/activities/class-activity-post.php
 create mode 100644 includes/activities/class-activity.php
 create mode 100644 includes/activities/class-query.php
 create mode 100644 includes/scan/class-posts.php

diff --git a/includes/activities/class-activity-post.php b/includes/activities/class-activity-post.php
new file mode 100644
index 000000000..0b6a4402a
--- /dev/null
+++ b/includes/activities/class-activity-post.php
@@ -0,0 +1,271 @@
+insert_post( $post_id, $post );
+	}
+
+	/**
+	 * Insert a post.
+	 *
+	 * Runs on wp_insert_post hook.
+	 *
+	 * @param int     $post_id The post ID.
+	 * @param WP_Post $post    The post object.
+	 * @return void
+	 */
+	public function insert_post( $post_id, $post ) {
+		// Bail if the post is not included in the post-types we're tracking.
+		$post_types = static::get_post_types_names();
+		if ( ! \in_array( $post->post_type, $post_types, true ) ) {
+			return;
+		}
+
+		// Bail if the post is not published.
+		if ( 'publish' !== $post->post_status ) {
+			return;
+		}
+
+		// Add a publish activity.
+		$activity = new Activity();
+		$activity->set_category( 'post' );
+		$activity->set_type( 'publish' );
+		$activity->set_date( Date::get_datetime_from_mysql_date( $post->post_date ) );
+		$activity->set_data_id( $post_id );
+		$activity->set_data(
+			[
+				'post_type'  => $post->post_type,
+				'word_count' => static::get_word_count( $post->post_content ),
+			]
+		);
+		$activity->save();
+	}
+
+	/**
+	 * Run actions when transitioning a post status.
+	 *
+	 * @param string   $new_status The new status.
+	 * @param string   $old_status The old status.
+	 * @param \WP_Post $post       The post object.
+	 */
+	public function transition_post_status( $new_status, $old_status, $post ) {
+
+		// If the post is published, check if it was previously published,
+		// and if so, delete the old activity and create a new one.
+		if ( 'publish' !== $old_status && 'publish' === $new_status ) {
+			$old_publish_activities = Query::get_instance()->query_activities(
+				[
+					'category' => 'post',
+					'type'     => 'publish',
+					'data_id'  => $post->ID,
+				]
+			);
+			if ( ! empty( $old_publish_activities ) ) {
+				foreach ( $old_publish_activities as $activity ) {
+					$activity->delete();
+				}
+			}
+
+			// Add a publish activity.
+			$activity = new Activity();
+			$activity->set_category( 'post' );
+			$activity->set_type( 'publish' );
+			$activity->set_date( Date::get_datetime_from_mysql_date( $post->post_date ) );
+			$activity->set_data_id( $post->ID );
+			$activity->set_data(
+				[
+					'post_type'  => $post->post_type,
+					'word_count' => static::get_word_count( $post->post_content ),
+				]
+			);
+			return $activity->save();
+		}
+
+		// Add an update activity.
+		$activity = new Activity();
+		$activity->set_category( 'post' );
+		$activity->set_type( 'update' );
+		$activity->set_date( Date::get_datetime_from_mysql_date( $post->post_modified ) );
+		$activity->set_data_id( $post->ID );
+		$activity->set_data(
+			[
+				'post_type'  => $post->post_type,
+				'word_count' => static::get_word_count( $post->post_content ),
+			]
+		);
+		return $activity->save();
+	}
+
+	/**
+	 * Update a post.
+	 *
+	 * Runs on pre_post_update hook.
+	 *
+	 * @param int     $post_id The post ID.
+	 * @param WP_Post $post    The post object.
+	 *
+	 * @return bool
+	 */
+	public function pre_post_update( $post_id, $post ) {
+		// Add an update activity.
+		$activity = new Activity();
+		$activity->set_category( 'post' );
+		$activity->set_type( 'update' );
+		$activity->set_date( Date::get_datetime_from_mysql_date( $post->post_modified ) );
+		$activity->set_data_id( $post->ID );
+		$activity->set_data(
+			[
+				'post_type'  => $post->post_type,
+				'word_count' => static::get_word_count( $post->post_content ),
+			]
+		);
+		return $activity->save();
+	}
+
+	/**
+	 * Trash a post.
+	 *
+	 * Runs on wp_trash_post hook.
+	 *
+	 * @param int $post_id The post ID.
+	 * @return void
+	 */
+	public function trash_post( $post_id ) {
+		$post = \get_post( $post_id );
+
+		// Bail if the post is not included in the post-types we're tracking.
+		$post_types = static::get_post_types_names();
+		if ( ! \in_array( $post->post_type, $post_types, true ) ) {
+			return;
+		}
+
+		// Add an update activity.
+		$activity = new Activity();
+		$activity->set_category( 'post' );
+		$activity->set_type( 'update' );
+		$activity->set_date( Date::get_datetime_from_mysql_date( $post->post_modified ) );
+		$activity->set_data_id( $post->ID );
+		$activity->set_data(
+			[
+				'post_type'  => $post->post_type,
+				'word_count' => static::get_word_count( $post->post_content ),
+			]
+		);
+		return $activity->save();
+	}
+
+	/**
+	 * Delete a post.
+	 *
+	 * Runs on delete_post hook.
+	 *
+	 * @param int $post_id The post ID.
+	 * @return void
+	 */
+	public function delete_post( $post_id ) {
+		$post = \get_post( $post_id );
+
+		// Bail if the post is not included in the post-types we're tracking.
+		$post_types = static::get_post_types_names();
+		if ( ! \in_array( $post->post_type, $post_types, true ) ) {
+			return;
+		}
+
+		// Update existing activities, and remove the words count.
+		$activities = Query::get_instance()->query_activities(
+			[
+				'category' => 'post',
+				'data_id'  => $post->ID,
+			]
+		);
+		if ( ! empty( $activities ) ) {
+			foreach ( $activities as $activity ) {
+				$activity->set_data( [ 'post_type' => $post->post_type ] );
+				$activity->save();
+			}
+			Query::get_instance()->delete_activities( $activities );
+		}
+
+		$activity = new Activity();
+		$activity->set_category( 'post' );
+		$activity->set_type( 'delete' );
+		$activity->set_date( Date::get_datetime_from_mysql_date( $post->post_date ) );
+		$activity->set_data_id( $post->ID );
+		$activity->save();
+	}
+
+	/**
+	 * Get an array of post-types names for the stats.
+	 *
+	 * @return string[]
+	 */
+	public static function get_post_types_names() {
+		$post_types = \get_post_types( [ 'public' => true ] );
+		unset( $post_types['attachment'] );
+
+		return array_keys( $post_types );
+	}
+
+	/**
+	 * Get words count from content.
+	 *
+	 * This method will render shortcodes, blocks,
+	 * and strip HTML before counting the words.
+	 *
+	 * @param string $content The content.
+	 *
+	 * @return int
+	 */
+	public static function get_word_count( $content ) {
+		// Parse blocks and shortcodes.
+		$content = \do_blocks( \do_shortcode( $content ) );
+
+		// Strip HTML.
+		$content = \wp_strip_all_tags( $content, true );
+
+		// Count words.
+		return \str_word_count( $content );
+	}
+}
diff --git a/includes/activities/class-activity.php b/includes/activities/class-activity.php
new file mode 100644
index 000000000..5f0fa623e
--- /dev/null
+++ b/includes/activities/class-activity.php
@@ -0,0 +1,197 @@
+id = $id;
+	}
+
+	/**
+	 * Get the ID of the activity.
+	 *
+	 * @return int
+	 */
+	public function get_id() {
+		return $this->id;
+	}
+
+	/**
+	 * Set the date.
+	 *
+	 * @param \DateTime $date The date of the activity.
+	 */
+	public function set_date( \DateTime $date ) {
+		$this->date = $date;
+	}
+
+	/**
+	 * Get the date of the activity.
+	 *
+	 * @return \DateTime
+	 */
+	public function get_date() {
+		return $this->date;
+	}
+
+	/**
+	 * Set the category.
+	 *
+	 * @param string $category The category of the activity.
+	 */
+	public function set_category( string $category ) {
+		$this->category = $category;
+	}
+
+	/**
+	 * Get the category of the activity.
+	 *
+	 * @return string
+	 */
+	public function get_category() {
+		return $this->category;
+	}
+
+	/**
+	 * Set the type.
+	 *
+	 * @param string $type The type of the activity.
+	 */
+	public function set_type( string $type ) {
+		$this->type = $type;
+	}
+
+	/**
+	 * Get the type of the activity.
+	 *
+	 * @return string
+	 */
+	public function get_type() {
+		return $this->type;
+	}
+
+	/**
+	 * Set the data ID.
+	 *
+	 * @param int $data_id The data ID.
+	 */
+	public function set_data_id( int $data_id ) {
+		$this->data_id = $data_id;
+	}
+
+	/**
+	 * Get the data ID.
+	 *
+	 * @return int
+	 */
+	public function get_data_id() {
+		return $this->data_id;
+	}
+
+	/**
+	 * Set the data of the activity.
+	 *
+	 * @param array $data The data of the activity.
+	 */
+	public function set_data( array $data ) {
+		$this->data = $data;
+	}
+
+	/**
+	 * Get the data of the activity.
+	 *
+	 * @return array
+	 */
+	public function get_data() {
+		return $this->data;
+	}
+
+	/**
+	 * Save the activity.
+	 *
+	 * @return void
+	 */
+	public function save() {
+		$existing = Query::get_instance()->query_activities(
+			[
+				'category' => $this->category,
+				'type'     => $this->type,
+				'data_id'  => $this->data_id,
+			]
+		);
+		if ( ! empty( $existing ) ) {
+			Query::get_instance()->update_activity( $existing[0]->id, $this );
+		} else {
+			Query::get_instance()->insert_activity( $this );
+		}
+	}
+
+	/**
+	 * Delete the activity.
+	 *
+	 * @return void
+	 */
+	public function delete() {
+		Query::get_instance()->delete_activity( $this );
+	}
+}
diff --git a/includes/activities/class-query.php b/includes/activities/class-query.php
new file mode 100644
index 000000000..39fad776c
--- /dev/null
+++ b/includes/activities/class-query.php
@@ -0,0 +1,350 @@
+create_tables();
+	}
+
+	/**
+	 * Create database tables.
+	 *
+	 * @return void
+	 */
+	public function create_tables() {
+		$this->create_activities_table();
+	}
+
+	/**
+	 * Create the activities table.
+	 *
+	 * @return void
+	 */
+	private function create_activities_table() {
+		global $wpdb;
+
+		$table_name      = $wpdb->prefix . static::TABLE_NAME;
+		$charset_collate = $wpdb->get_charset_collate();
+
+		/**
+		 * Create a table for activities.
+		 *
+		 * Columns:
+		 * - date: The date of the activity.
+		 * - category: The category of the activity.
+		 * - type: The type of the activity.
+		 * - data_id: The ID of the data of the activity.
+		 * - data: The data of the activity.
+		 */
+		// phpcs:disable WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL
+		$wpdb->query(
+			"CREATE TABLE IF NOT EXISTS $table_name (
+				id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
+				date DATE NOT NULL,
+				category VARCHAR(255) NOT NULL,
+				type VARCHAR(255) NOT NULL,
+				data_id BIGINT(20) UNSIGNED NOT NULL,
+				data LONGTEXT NOT NULL,
+				PRIMARY KEY (id)
+			) $charset_collate;"
+		);
+	}
+
+	/**
+	 * Query the database for activities.
+	 *
+	 * @param array $args The arguments for the query.
+	 *
+	 * @return \ProgressPlanner\Activities\Activity[] The activities.
+	 */
+	public function query_activities( $args ) {
+		global $wpdb;
+
+		$defaults = [
+			'start_date' => null,
+			'end_date'   => null,
+			'category'   => '%',
+			'type'       => '%',
+			'data_id'    => '%',
+		];
+
+		$args = \wp_parse_args( $args, $defaults );
+
+		// If start and end dates are defined, then get activities by date.
+		if ( $args['start_date'] && $args['end_date'] ) {
+			// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
+			$results = $wpdb->get_results(
+				$wpdb->prepare(
+					'SELECT * FROM %i WHERE date >= %s AND date <= %s AND category LIKE %s AND type LIKE %s AND data_id LIKE %s',
+					$wpdb->prefix . static::TABLE_NAME,
+					$args['start_date']->format( 'Y-m-d' ),
+					$args['end_date']->format( 'Y-m-d' ),
+					$args['category'],
+					$args['type'],
+					$args['data_id']
+				)
+			);
+		} else {
+			// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
+			$results = $wpdb->get_results(
+				$wpdb->prepare(
+					'SELECT * FROM %i WHERE category LIKE %s AND type LIKE %s AND data_id LIKE %s',
+					$wpdb->prefix . static::TABLE_NAME,
+					$args['category'],
+					$args['type'],
+					$args['data_id']
+				)
+			);
+		}
+
+		$activities = $this->get_activities_from_results( $results );
+
+		if ( isset( $args['data'] ) && ! empty( $args['data'] ) ) {
+			foreach ( $activities as $key => $activity ) {
+				$data = $activity->get_data();
+				foreach ( $args['data'] as $data_key => $data_value ) {
+					if ( ! isset( $data[ $data_key ] ) || $data[ $data_key ] !== $data_value ) {
+						unset( $activities[ $key ] );
+					}
+				}
+			}
+			$activities = \array_values( $activities );
+		}
+		return $activities;
+	}
+
+	/**
+	 * Insert multiple activities into the database.
+	 *
+	 * @param \ProgressPlanner\Activities\Activity[] $activities The activities to insert.
+	 *
+	 * @return int[]|false The IDs of the inserted activities, or false on failure.
+	 */
+	public function insert_activities( $activities ) {
+		$ids = [];
+		foreach ( $activities as $activity ) {
+			$id = $this->insert_activity( $activity );
+			if ( false === $id ) {
+				continue;
+			}
+			$ids[] = $id;
+		}
+		if ( empty( $ids ) ) {
+			return false;
+		}
+		return $ids;
+	}
+
+
+	/**
+	 * Insert an activity into the database.
+	 *
+	 * @param \ProgressPlanner\Activities\Activity $activity The activity to insert.
+	 *
+	 * @return int|false The ID of the inserted activity, or false on failure.
+	 */
+	public function insert_activity( $activity ) {
+		global $wpdb;
+
+		// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
+		$result = $wpdb->insert(
+			$wpdb->prefix . static::TABLE_NAME,
+			[
+				'date'     => $activity->get_date()->format( 'Y-m-d H:i:s' ),
+				'category' => $activity->get_category(),
+				'type'     => $activity->get_type(),
+				'data_id'  => $activity->get_data_id(),
+				'data'     => \wp_json_encode( $activity->get_data() ),
+			],
+			[
+				'%s',
+				'%s',
+				'%s',
+				'%s',
+			]
+		);
+
+		if ( false === $result ) {
+			return false;
+		}
+
+		return (int) $wpdb->insert_id;
+	}
+
+	/**
+	 * Get activities objects from results.
+	 *
+	 * @param array $results The results.
+	 *
+	 * @return \ProgressPlanner\Activities\Activity[] The activities.
+	 */
+	private function get_activities_from_results( $results ) {
+		$activities = [];
+		foreach ( $results as $result ) {
+			$activity = new Activity();
+			$activity->set_date( new \DateTime( $result->date ) );
+			$activity->set_category( $result->category );
+			$activity->set_type( $result->type );
+			$activity->set_data_id( (int) $result->data_id );
+			$activity->set_data( \json_decode( $result->data, true ) );
+			$activity->set_id( (int) $result->id );
+			$activities[] = $activity;
+		}
+
+		return $activities;
+	}
+
+	/**
+	 * Update an activity in the database.
+	 *
+	 * @param int                                  $id       The ID of the activity to update.
+	 * @param \ProgressPlanner\Activities\Activity $activity The activity to update.
+	 *
+	 * @return void
+	 */
+	public function update_activity( $id, $activity ) {
+		global $wpdb;
+
+		// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
+		$wpdb->update(
+			$wpdb->prefix . static::TABLE_NAME,
+			[
+				'date'     => $activity->get_date()->format( 'Y-m-d H:i:s' ),
+				'category' => $activity->get_category(),
+				'type'     => $activity->get_type(),
+				'data_id'  => $activity->get_data_id(),
+				'data'     => \wp_json_encode( $activity->get_data() ),
+			],
+			[ 'id' => $id ],
+			[
+				'%s',
+				'%s',
+				'%s',
+				'%s',
+				'%s',
+			],
+			[ '%d' ]
+		);
+	}
+
+	/**
+	 * Delete activities from the database.
+	 *
+	 * @param \ProgressPlanner\Activities\Activity[] $activities The activity to delete.
+	 *
+	 * @return void
+	 */
+	public function delete_activities( $activities ) {
+		foreach ( $activities as $activity ) {
+			$this->delete_activity( $activity );
+		}
+	}
+
+	/**
+	 * Delete an activity from the database.
+	 *
+	 * @param \ProgressPlanner\Activities\Activity $activity The activity to delete.
+	 *
+	 * @return void
+	 */
+	public function delete_activity( $activity ) {
+		global $wpdb;
+
+		// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
+		$wpdb->delete(
+			$wpdb->prefix . static::TABLE_NAME,
+			[ 'id' => $activity->get_id() ],
+			[ '%d' ]
+		);
+	}
+
+	/**
+	 * Detele all activities in a category.
+	 *
+	 * @param string $category The category of the activities to delete.
+	 *
+	 * @return void
+	 */
+	public function delete_category_activities( $category ) {
+		global $wpdb;
+
+		// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
+		$wpdb->delete(
+			$wpdb->prefix . static::TABLE_NAME,
+			[ 'category' => $category ],
+			[ '%s' ]
+		);
+	}
+
+	/**
+	 * Get oldest activity.
+	 *
+	 * @return \ProgressPlanner\Activities\Activity
+	 */
+	public function get_oldest_activity() {
+		global $wpdb;
+
+		// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
+		$result = $wpdb->get_row(
+			$wpdb->prepare(
+				'SELECT * FROM %i ORDER BY date ASC LIMIT 1',
+				$wpdb->prefix . static::TABLE_NAME
+			)
+		);
+
+		$activity = new Activity();
+		$activity->set_date( new \DateTime( $result->date ) );
+		$activity->set_category( $result->category );
+		$activity->set_type( $result->type );
+		$activity->set_data_id( (int) $result->data_id );
+		$activity->set_data( \json_decode( $result->data, true ) );
+		$activity->set_id( (int) $result->id );
+
+		return $activity;
+	}
+}
+// phpcs:enable
diff --git a/includes/admin/class-page.php b/includes/admin/class-page.php
index 2688c007e..1d630c3ed 100644
--- a/includes/admin/class-page.php
+++ b/includes/admin/class-page.php
@@ -109,8 +109,7 @@ public function ajax_scan() {
 		}
 
 		// Scan the posts.
-		$posts_stats   = new \ProgressPlanner\Stats\Stat_Posts();
-		$updated_stats = $posts_stats->update_stats();
+		$updated_stats = \ProgressPlanner\Scan\Posts::update_stats();
 
 		\wp_send_json_success(
 			[
@@ -136,8 +135,7 @@ public function ajax_reset_stats() {
 		}
 
 		// Reset the stats.
-		$posts_stats = new \ProgressPlanner\Stats\Stat_Posts();
-		$posts_stats->reset_stats();
+		\ProgressPlanner\Scan\Posts::reset_stats();
 
 		\wp_send_json_success(
 			[
diff --git a/includes/charts/class-posts.php b/includes/charts/class-posts.php
index ba6eae17e..05d9d641a 100644
--- a/includes/charts/class-posts.php
+++ b/includes/charts/class-posts.php
@@ -8,8 +8,7 @@
 namespace ProgressPlanner\Charts;
 
 use ProgressPlanner\Chart;
-use ProgressPlanner\Date;
-use ProgressPlanner\Stats\Stat_Posts;
+use ProgressPlanner\Activities\Query;
 
 /**
  * Posts chart.
@@ -19,7 +18,7 @@ class Posts extends Chart {
 	/**
 	 * Build a chart for the stats.
 	 *
-	 * @param array  $post_types The post types.
+	 * @param string $post_type  The post type.
 	 * @param string $context    The context for the chart. Can be 'count' or 'words'.
 	 * @param string $interval   The interval for the chart. Can be 'days', 'weeks', 'months', 'years'.
 	 * @param int    $range      The number of intervals to show.
@@ -27,7 +26,7 @@ class Posts extends Chart {
 	 *
 	 * @return void
 	 */
-	public function render( $post_types = [], $context = 'count', $interval = 'weeks', $range = 10, $offset = 0 ) {
+	public function render( $post_type = 'post', $context = 'count', $interval = 'weeks', $range = 10, $offset = 0 ) {
 		$range_array_end   = \range( $offset, $range - 1 );
 		$range_array_start = \range( $offset + 1, $range );
 		\krsort( $range_array_start );
@@ -40,59 +39,60 @@ public function render( $post_types = [], $context = 'count', $interval = 'weeks
 			'datasets' => [],
 		];
 		$datasets               = [];
-		$post_type_count_totals = [];
-		foreach ( $post_types as $post_type ) {
-			$post_type_count_totals[ $post_type ] = 0;
-			$datasets[ $post_type ]               = [
-				'label'   => \get_post_type_object( $post_type )->label,
-				'data'    => [],
-				'tension' => 0.2,
-			];
-		}
-
-		$stat_posts = new Stat_Posts();
+		$post_type_count_totals = 0;
+		$dataset                = [
+			'label'   => \get_post_type_object( $post_type )->label,
+			'data'    => [],
+			'tension' => 0.2,
+		];
 
 		// Calculate zero stats to be used as the baseline.
-		$zero_stats = $stat_posts->get_stats(
-			19700101,
-			(int) gmdate( Date::FORMAT, strtotime( "-$range $interval" ) ),
-			$post_types
+		$zero_activities = Query::get_instance()->query_activities(
+			[
+				'category'   => 'post',
+				'type'       => 'publish',
+				'start_date' => \DateTime::createFromFormat( 'Y-m-d', '1970-01-01' ),
+				'end_date'   => new \DateTime( "-$range $interval" ),
+				'data'       => [
+					'post_type' => $post_type,
+				],
+			]
 		);
-		foreach ( $zero_stats as $zero_posts ) {
-			foreach ( $zero_posts as $zero_post ) {
-				$post_type_count_totals[ $zero_post['post_type'] ] += 'words' === $context
-					? $zero_post['words']
-					: 1;
-			}
+		foreach ( $zero_activities as $zero_activity ) {
+			$activity_data           = $zero_activity->get_data();
+			$post_type_count_totals += 'words' === $context
+				? $activity_data['word_count']
+				: 1;
 		}
 
 		foreach ( $range_array as $start => $end ) {
-			$stats = $stat_posts->get_stats(
-				(int) gmdate( Date::FORMAT, strtotime( "-$start $interval" ) ),
-				(int) gmdate( Date::FORMAT, strtotime( "-$end $interval" ) ),
-				$post_types
+			$activities = Query::get_instance()->query_activities(
+				[
+					'category'   => 'post',
+					'type'       => 'publish',
+					'start_date' => new \DateTime( "-$start $interval" ),
+					'end_date'   => new \DateTime( "-$end $interval" ),
+					'data'       => [
+						'post_type' => $post_type,
+					],
+				]
 			);
 
 			// TODO: Format the date depending on the user's locale.
 			$data['labels'][] = gmdate( 'Y-m-d', strtotime( "-$start $interval" ) );
 
-			foreach ( $post_types as $post_type ) {
-				foreach ( $stats as $posts ) {
-					foreach ( $posts as $post_details ) {
-						if ( $post_details['post_type'] === $post_type ) {
-							$post_type_count_totals[ $post_type ] += 'words' === $context
-								? $post_details['words']
-								: 1;
-						}
-					}
-				}
-				$datasets[ $post_type ]['data'][] = $post_type_count_totals[ $post_type ];
+			foreach ( $activities as $activity ) {
+				$activity_data           = $activity->get_data();
+				$post_type_count_totals += 'words' === $context
+					? $activity_data['word_count']
+					: 1;
 			}
+			$datasets[ $post_type ]['data'][] = $post_type_count_totals;
 		}
 		$data['datasets'] = \array_values( $datasets );
 
 		$this->render_chart(
-			md5( wp_json_encode( [ $post_types, $context, $interval, $range, $offset ] ) ),
+			md5( wp_json_encode( [ [ $post_type ], $context, $interval, $range, $offset ] ) ),
 			'line',
 			$data,
 			[]
diff --git a/includes/class-date.php b/includes/class-date.php
index c420d7a59..e8b3150a7 100644
--- a/includes/class-date.php
+++ b/includes/class-date.php
@@ -12,13 +12,6 @@
  */
 class Date {
 
-	/**
-	 * Date format.
-	 *
-	 * @var string
-	 */
-	const FORMAT = 'Ymd';
-
 	/**
 	 * Get a range of dates.
 	 *
@@ -32,19 +25,10 @@ class Date {
 	 *               ].
 	 */
 	public function get_range( $start, $end ) {
-		$start = \DateTime::createFromFormat( self::FORMAT, $start );
-		$end   = \DateTime::createFromFormat( self::FORMAT, $end );
-
-		$dates = [];
-		$range = new \DatePeriod( $start, new \DateInterval( 'P1D' ), $end );
-		foreach ( $range as $date ) {
-			$dates[] = $date->format( self::FORMAT );
-		}
-
 		return [
-			'start' => $start->format( self::FORMAT ),
-			'end'   => $end->format( self::FORMAT ),
-			'dates' => $dates,
+			'start' => $start,
+			'end'   => $end,
+			'dates' => iterator_to_array( new \DatePeriod( $start, new \DateInterval( 'P1D' ), $end ), false ),
 		];
 	}
 
@@ -58,9 +42,7 @@ public function get_range( $start, $end ) {
 	 * @return array
 	 */
 	public function get_periods( $start, $end, $frequency ) {
-		$start = \DateTime::createFromFormat( self::FORMAT, $start );
-		$end   = \DateTime::createFromFormat( self::FORMAT, $end );
-		$end   = $end->modify( '+1 day' );
+		$end = $end->modify( '+1 day' );
 
 		switch ( $frequency ) {
 			case 'daily':
@@ -79,26 +61,26 @@ public function get_periods( $start, $end, $frequency ) {
 				break;
 		}
 
-		$period      = new \DatePeriod( $start, $interval, $end );
-		$dates_array = [];
-		foreach ( $period as $date ) {
-			$dates_array[] = $date->format( self::FORMAT );
-		}
+		$period = iterator_to_array( new \DatePeriod( $start, $interval, $end ), false );
 
 		$date_ranges = [];
-		foreach ( $dates_array as $key => $date ) {
-			if ( isset( $dates_array[ $key + 1 ] ) ) {
-				$datetime = \DateTime::createFromFormat( self::FORMAT, $dates_array[ $key + 1 ] );
-				if ( ! $datetime ) {
-					continue;
-				}
-				$date_ranges[] = $this->get_range(
-					$date,
-					$datetime->format( self::FORMAT )
-				);
+		foreach ( $period as $key => $date ) {
+			if ( isset( $period[ $key + 1 ] ) ) {
+				$date_ranges[] = $this->get_range( $date, $period[ $key + 1 ] );
 			}
 		}
 
 		return $date_ranges;
 	}
+
+	/**
+	 * Get DateTime object from a mysql date.
+	 *
+	 * @param string $date The date.
+	 *
+	 * @return \DateTime
+	 */
+	public static function get_datetime_from_mysql_date( $date ) {
+		return \DateTime::createFromFormat( 'U', (int) mysql2date( 'U', $date ) );
+	}
 }
diff --git a/includes/class-stats.php b/includes/class-stats.php
index d08c22842..2b23c8948 100644
--- a/includes/class-stats.php
+++ b/includes/class-stats.php
@@ -70,4 +70,20 @@ public function get_stat( $id ) {
 	private function register_stats() {
 		$this->add_stat( 'posts', new Stat_Posts() );
 	}
+
+	/**
+	 * Get number of activities for date range.
+	 *
+	 * @param \DateTime $start_date The start date.
+	 * @param \DateTime $end_date   The end date.
+	 * @param array     $args       The query arguments.
+	 *
+	 * @return int
+	 */
+	public function get_number_of_activities( $start_date, $end_date, $args = [] ) {
+		$args['start_date'] = $start_date;
+		$args['end_date']   = $end_date;
+		$activities = Query::get_instance()->query_activities( $args );
+		return count( $activities );
+	}
 }
diff --git a/includes/class-streaks.php b/includes/class-streaks.php
index 689e75074..e38953426 100644
--- a/includes/class-streaks.php
+++ b/includes/class-streaks.php
@@ -9,7 +9,7 @@
 
 use ProgressPlanner\Goals\Goal_Posts;
 use ProgressPlanner\Goals\Goal_Recurring;
-use ProgressPlanner\Stats\Stat_Posts;
+use ProgressPlanner\Activities\Query;
 
 /**
  * Streaks class.
@@ -113,15 +113,6 @@ public function get_streak( $goal_id, $target ) {
 	 * @return void
 	 */
 	private function get_weekly_post_goal() {
-		$stats = new Stat_Posts();
-
-		$stats_value = $stats->get_value();
-
-		// Bail early if there are no stats.
-		if ( empty( $stats_value ) ) {
-			return;
-		}
-
 		return new Goal_Recurring(
 			new Goal_Posts(
 				[
@@ -130,20 +121,26 @@ private function get_weekly_post_goal() {
 					'description' => \esc_html__( 'Streak: The number of weeks this goal has been accomplished consistently.', 'progress-planner' ),
 					'status'      => 'active',
 					'priority'    => 'low',
-					'evaluate'    => function ( $goal_object ) use ( $stats ) {
+					'evaluate'    => function ( $goal_object ) {
 						return (bool) count(
-							$stats->get_stats(
-								$goal_object->get_details()['start_date'],
-								$goal_object->get_details()['end_date'],
-								[]
+							Query::get_instance()->query_activities(
+								[
+									'category'   => 'post',
+									'type'       => 'publish',
+									'start_date' => $goal_object->get_details()['start_date'],
+									'end_date'   => $goal_object->get_details()['end_date'],
+									'data'       => [
+										'post_type' => 'post',
+									],
+								]
 							)
 						);
 					},
 				]
 			),
 			'weekly',
-			array_keys( $stats_value )[0], // Beginning of the stats.
-			gmdate( Date::FORMAT ) // Today.
+			Query::get_instance()->get_oldest_activity()->get_date(), // Beginning of the stats.
+			new \DateTime( 'now' ) // Today.
 		);
 	}
 
@@ -153,42 +150,37 @@ private function get_weekly_post_goal() {
 	 * @return void
 	 */
 	private function get_weekly_words_goal() {
-		$stats = new Stat_Posts();
-
-		$stats_value = $stats->get_value();
-
-		// Bail early if there are no stats.
-		if ( empty( $stats_value ) ) {
-			return;
-		}
-
 		return new Goal_Recurring(
 			new Goal_Posts(
 				[
-					'id'          => 'weekly_words',
-					'title'       => \esc_html__( 'Write 500 words/week', 'progress-planner' ),
+					'id'          => 'weekly_post',
+					'title'       => \esc_html__( 'Write a weekly blog post', 'progress-planner' ),
 					'description' => \esc_html__( 'Streak: The number of weeks this goal has been accomplished consistently.', 'progress-planner' ),
 					'status'      => 'active',
 					'priority'    => 'low',
-					'evaluate'    => function ( $goal_object ) use ( $stats ) {
-						$words = 0;
-						$posts = $stats->get_stats(
-							$goal_object->get_details()['start_date'],
-							$goal_object->get_details()['end_date'],
-							[ 'post' ]
+					'evaluate'    => function ( $goal_object ) {
+						$activities = Query::get_instance()->query_activities(
+							[
+								'category'   => 'post',
+								'type'       => 'publish',
+								'start_date' => $goal_object->get_details()['start_date'],
+								'end_date'   => $goal_object->get_details()['end_date'],
+								'data'       => [
+									'post_type' => 'post',
+								],
+							]
 						);
-						foreach ( $posts as $post_dates ) {
-							foreach ( $post_dates as $post_details ) {
-								$words += $post_details['words'];
-							}
+						$words      = 0;
+						foreach ( $activities as $activity ) {
+							$words += $activity->get_data()['word_count'];
 						}
 						return $words >= 500;
 					},
 				]
 			),
 			'weekly',
-			array_keys( $stats_value )[0], // Beginning of the stats.
-			gmdate( Date::FORMAT ) // Today.
+			Query::get_instance()->get_oldest_activity()->get_date(), // Beginning of the stats.
+			new \DateTime( 'now' ) // Today.
 		);
 	}
 }
diff --git a/includes/goals/class-goal-recurring.php b/includes/goals/class-goal-recurring.php
index 8af6271ed..584e8017b 100644
--- a/includes/goals/class-goal-recurring.php
+++ b/includes/goals/class-goal-recurring.php
@@ -82,15 +82,14 @@ public function get_occurences() {
 		if ( ! empty( $this->occurences ) ) {
 			return $this->occurences;
 		}
-
 		$date   = new Date();
 		$ranges = $date->get_periods( $this->start, $this->end, $this->frequency );
 
 		// If the last range ends before today, add a new range.
-		if ( (int) gmdate( Date::FORMAT ) > (int) end( $ranges )['end'] ) {
+		if ( (int) gmdate( 'Ymd' ) > (int) end( $ranges )['end']->format( 'Ymd' ) ) {
 			$ranges[] = $date->get_range(
 				end( $ranges )['end'],
-				gmdate( Date::FORMAT, strtotime( '+1 day' ) ),
+				new \DateTime( 'tomorrow' )
 			);
 		}
 
diff --git a/includes/scan/class-posts.php b/includes/scan/class-posts.php
new file mode 100644
index 000000000..c280f05d2
--- /dev/null
+++ b/includes/scan/class-posts.php
@@ -0,0 +1,120 @@
+publish;
+		}
+		// Calculate the total pages to scan.
+		$total_pages = \ceil( $total_posts_count / static::SCAN_POSTS_PER_PAGE );
+		// Get the last scanned page.
+		$last_page = (int) \get_option( static::LAST_SCANNED_PAGE_OPTION, 0 );
+		// The current page to scan.
+		$current_page = $last_page + 1;
+
+		// Get posts.
+		$posts = \get_posts(
+			[
+				'posts_per_page' => static::SCAN_POSTS_PER_PAGE,
+				'paged'          => $current_page,
+				'post_type'      => Activity_Post::get_post_types_names(),
+				'post_status'    => 'any',
+			]
+		);
+
+		if ( ! $posts ) {
+			\delete_option( static::LAST_SCANNED_PAGE_OPTION );
+			return [
+				'lastScannedPage' => $last_page,
+				'lastPage'        => $total_pages,
+				'progress'        => 100,
+			];
+		}
+
+		// Loop through the posts and update the stats.
+		foreach ( $posts as $post ) {
+			$activity = new Activity();
+			$activity->set_category( 'post' );
+			$activity->set_data_id( $post->ID );
+			$activity->set_data(
+				[
+					'post_type'  => $post->post_type,
+					'word_count' => Activity_Post::get_word_count( $post->post_content ),
+				]
+			);
+
+			switch ( $post->post_status ) {
+				case 'publish':
+					$activity->set_type( 'publish' );
+					$activity->set_date( Date::get_datetime_from_mysql_date( $post->post_date ) );
+					break;
+
+				default:
+					$activity->set_type( 'update' );
+					$activity->set_date( Date::get_datetime_from_mysql_date( $post->post_modified ) );
+			}
+
+			$activity->save();
+		}
+
+		\update_option( static::LAST_SCANNED_PAGE_OPTION, $current_page );
+
+		return [
+			'lastScannedPage' => $last_page,
+			'lastPage'        => $total_pages,
+			'progress'        => round( ( $current_page / max( 1, $total_pages ) ) * 100 ),
+		];
+	}
+
+	/**
+	 * Reset the stats in our database.
+	 *
+	 * @return void
+	 */
+	public static function reset_stats() {
+		Query::get_instance()->delete_category_activities( 'post' );
+		\delete_option( static::LAST_SCANNED_PAGE_OPTION );
+	}
+}
diff --git a/includes/stats/class-stat-posts.php b/includes/stats/class-stat-posts.php
index 92006931a..e96a5e3b6 100644
--- a/includes/stats/class-stat-posts.php
+++ b/includes/stats/class-stat-posts.php
@@ -7,314 +7,24 @@
 
 namespace ProgressPlanner\Stats;
 
-use ProgressPlanner\Date;
+use ProgressPlanner\Activities\Query;
 
 /**
  * Stats about posts.
  */
 class Stat_Posts {
 
-	/**
-	 * The setting name.
-	 *
-	 * @var string
-	 */
-	const SETTING_NAME = 'progress_planner_stats_posts';
-
-	/**
-	 * The number of posts to scan at a time.
-	 *
-	 * @var int
-	 */
-	const SCAN_POSTS_PER_PAGE = 20;
-
-	/**
-	 * The option used to store the last scanned page.
-	 *
-	 * @var string
-	 */
-	const LAST_SCANNED_PAGE_OPTION = 'progress_planner_stats_last_scanned_page';
-
-	/**
-	 * The stats. Used for caching purposes.
-	 *
-	 * @var array
-	 */
-	private static $stats;
-
-	/**
-	 * Constructor.
-	 */
-	public function __construct() {
-		$this->register_hooks();
-	}
-
-	/**
-	 * Register the hooks.
-	 *
-	 * @return void
-	 */
-	private function register_hooks() {
-		\add_action( 'save_post', [ $this, 'save_post' ], 10, 2 );
-		\add_action( 'wp_insert_post', [ $this, 'save_post' ], 10, 2 );
-		\add_action( 'delete_post', [ $this, 'delete_post' ] );
-		\add_action( 'transition_post_status', [ $this, 'transition_post_status' ], 10, 3 );
-	}
-
-	/**
-	 * Run actions when saving a post.
-	 *
-	 * @param int      $post_id The post ID.
-	 * @param \WP_Post $post    The post object.
-	 */
-	public function save_post( $post_id, $post ) {
-		// Bail if the post is not included in the post-types we're tracking.
-		$post_types = $this->get_post_types_names();
-		if ( ! \in_array( $post->post_type, $post_types, true ) ) {
-			return;
-		}
-
-		// Bail if the post is not published.
-		if ( 'publish' !== $post->post_status ) {
-			return;
-		}
-
-		$this->save_post_stats( $post );
-	}
-
-	/**
-	 * Delete a post from stats.
-	 *
-	 * @param int $post_id The post ID.
-	 */
-	public function delete_post( $post_id ) {
-		$value   = \get_option( static::SETTING_NAME, [] );
-		$updated = false;
-		// Remove the post from stats if it's already stored in another date.
-		foreach ( $value as $date_key => $date_value ) {
-			if ( isset( $date_value[ $post_id ] ) ) {
-				unset( $value[ $date_key ][ $post_id ] );
-				$updated = true;
-			}
-		}
-
-		if ( $updated ) {
-			\update_option( static::SETTING_NAME, $value );
-		}
-	}
-
-	/**
-	 * Run actions when transitioning a post status.
-	 *
-	 * @param string   $new_status The new status.
-	 * @param string   $old_status The old status.
-	 * @param \WP_Post $post       The post object.
-	 */
-	public function transition_post_status( $new_status, $old_status, $post ) {
-		// Delete the post from stats.
-		if ( 'publish' === $old_status && 'publish' !== $new_status ) {
-			$this->delete_post( $post->ID );
-		}
-		// Add the post to stats.
-		if ( 'publish' !== $old_status && 'publish' === $new_status ) {
-			$this->save_post_stats( $post );
-		}
-	}
-
 	/**
 	 * Get the value.
 	 *
 	 * @return mixed
 	 */
 	public function get_value() {
-		if ( ! self::$stats ) {
-			$value = \get_option( static::SETTING_NAME, [] );
-			ksort( $value );
-			self::$stats = $value;
-		}
-		return self::$stats;
-	}
-
-	/**
-	 * Save a post to the stats.
-	 *
-	 * @param \WP_Post $post The post.
-	 *
-	 * @return bool
-	 */
-	protected function save_post_stats( $post ) {
-		$value = \get_option( static::SETTING_NAME, [] );
-		$date  = (int) mysql2date( Date::FORMAT, $post->post_date );
-
-		// Remove the post from stats if it's already stored in another date.
-		foreach ( $value as $date_key => $date_value ) {
-			if ( isset( $date_value[ $post->ID ] ) ) {
-				unset( $value[ $date_key ][ $post->ID ] );
-			}
-		}
-
-		if ( ! isset( $value[ $date ] ) ) {
-			$value[ $date ] = [];
-		}
-		$value[ $date ][ $post->ID ] = [
-			'post_type' => $post->post_type,
-			'words'     => $this->get_word_count( $post->post_content ),
-		];
-		return \update_option( static::SETTING_NAME, $value );
-	}
-
-	/**
-	 * Get stats for date range.
-	 *
-	 * @param int|string $start_date The start date.
-	 * @param int|string $end_date   The end date.
-	 * @param string[]   $post_types The post types.
-	 *
-	 * @return array
-	 */
-	public function get_stats( $start_date, $end_date, $post_types = [] ) {
-		$stats = $this->get_value();
-
-		// Get the stats for the date range and post types.
-		foreach ( $stats as $date => $date_stats ) {
-			// Remove stats outside the date range.
-			if ( $date <= $start_date || $date > $end_date ) {
-				unset( $stats[ $date ] );
-				continue;
-			}
-
-			// If we have not defined post types, then we don't need to filter by post type.
-			if ( empty( $post_types ) ) {
-				continue;
-			}
-
-			// Remove stats not in the post types.
-			foreach ( $stats[ $date ] as $post_id => $details ) {
-				if ( ! \in_array( $details['post_type'], $post_types, true ) ) {
-					unset( $stats[ $date ][ $post_id ] );
-				}
-			}
-
-			// Remove empty dates.
-			if ( ! $stats[ $date ] || empty( $stats[ $date ] ) ) {
-				unset( $stats[ $date ] );
-				continue;
-			}
-		}
-
-		return $stats;
-	}
-
-	/**
-	 * Get an array of post-types names for the stats.
-	 *
-	 * @return string[]
-	 */
-	public function get_post_types_names() {
-		$post_types = \get_post_types( [ 'public' => true ] );
-		unset( $post_types['attachment'] );
-
-		return array_keys( $post_types );
-	}
-
-	/**
-	 * Get words count from content.
-	 *
-	 * This method will render shortcodes, blocks,
-	 * and strip HTML before counting the words.
-	 *
-	 * @param string $content The content.
-	 *
-	 * @return int
-	 */
-	protected function get_word_count( $content ) {
-		// Parse blocks and shortcodes.
-		$content = \do_blocks( \do_shortcode( $content ) );
-
-		// Strip HTML.
-		$content = \wp_strip_all_tags( $content, true );
-
-		// Count words.
-		return \str_word_count( $content );
-	}
-
-	/**
-	 * Update stats for posts.
-	 * - Gets the next page to scan.
-	 * - Gets the posts for the page.
-	 * - Updates the stats for the posts.
-	 * - Updates the last scanned page option.
-	 *
-	 * @return array
-	 */
-	public function update_stats() {
-
-		// Get the total number of posts.
-		$total_posts_count = 0;
-		foreach ( $this->get_post_types_names() as $post_type ) {
-			$total_posts_count += \wp_count_posts( $post_type )->publish;
-		}
-		// Calculate the total pages to scan.
-		$total_pages = \ceil( $total_posts_count / static::SCAN_POSTS_PER_PAGE );
-		// Get the last scanned page.
-		$last_page = (int) \get_option( static::LAST_SCANNED_PAGE_OPTION, 0 );
-		// The current page to scan.
-		$current_page = $last_page + 1;
-
-		// Get posts.
-		$posts = \get_posts(
+		return Query::get_instance()->query_activities(
 			[
-				'posts_per_page' => static::SCAN_POSTS_PER_PAGE,
-				'paged'          => $current_page,
-				'post_type'      => $this->get_post_types_names(),
-				'post_status'    => 'publish',
+				'category' => 'post',
+				'type'     => 'publish',
 			]
 		);
-
-		if ( $posts ) {
-			// Get the value from the option.
-			$value = \get_option( static::SETTING_NAME, [] );
-
-			// Loop through the posts and update the $value stats.
-			foreach ( $posts as $post ) {
-				// Get the date from the post, and convert it to the format we use.
-				$date = (int) mysql2date( Date::FORMAT, $post->post_date );
-
-				// If the date is not set in the option, set it to an empty array.
-				if ( ! isset( $value[ $date ] ) ) {
-					$value[ $date ] = [];
-				}
-
-				// Add the post to the date.
-				$value[ $date ][ $post->ID ] = [
-					'post_type' => $post->post_type,
-					'words'     => $this->get_word_count( $post->post_content ),
-				];
-			}
-
-			// Save the option.
-			\update_option( static::SETTING_NAME, $value );
-		}
-
-		if ( $current_page > $total_pages ) {
-			\delete_option( static::LAST_SCANNED_PAGE_OPTION );
-		}
-		\update_option( static::LAST_SCANNED_PAGE_OPTION, $current_page );
-
-		return [
-			'lastScannedPage' => $last_page,
-			'lastPage'        => $total_pages,
-			'progress'        => round( ( $current_page / max( 1, $total_pages ) ) * 100 ),
-		];
-	}
-
-	/**
-	 * Reset the stats in our database.
-	 *
-	 * @return void
-	 */
-	public function reset_stats() {
-		\delete_option( static::SETTING_NAME );
-		\delete_option( static::LAST_SCANNED_PAGE_OPTION );
 	}
 }
diff --git a/progress-planner.php b/progress-planner.php
index f4e629505..dc4a2e116 100644
--- a/progress-planner.php
+++ b/progress-planner.php
@@ -11,3 +11,5 @@
 require_once PROGRESS_PLANNER_DIR . '/includes/autoload.php';
 
 \ProgressPlanner\Base::get_instance();
+
+$prpl_storage = \ProgressPlanner\Activities\Query::get_instance();
diff --git a/views/admin-page-debug.php b/views/admin-page-debug.php
index d3a3ae7c3..391c9681d 100644
--- a/views/admin-page-debug.php
+++ b/views/admin-page-debug.php
@@ -16,7 +16,7 @@
 	
 		get_value() );
+		print_r( \ProgressPlanner\Activities\Query::get_instance()->query_activities( [] ) );
 		?>
 	
diff --git a/views/admin-page-posts-count-progress.php b/views/admin-page-posts-count-progress.php index 9ae5d804f..e0c6448dd 100644 --- a/views/admin-page-posts-count-progress.php +++ b/views/admin-page-posts-count-progress.php @@ -11,7 +11,7 @@ echo ''; ( new \ProgressPlanner\Charts\Posts() )->render( - \ProgressPlanner\Admin\Page::get_params()['stats']->get_post_types_names(), + 'post', 'count', \ProgressPlanner\Admin\Page::get_params()['filter_interval'], \ProgressPlanner\Admin\Page::get_params()['filter_number'], diff --git a/views/admin-page-words-count-progress.php b/views/admin-page-words-count-progress.php index 2fad846f3..82ed0fa5b 100644 --- a/views/admin-page-words-count-progress.php +++ b/views/admin-page-words-count-progress.php @@ -11,7 +11,7 @@ echo ''; ( new \ProgressPlanner\Charts\Posts() )->render( - \ProgressPlanner\Admin\Page::get_params()['stats']->get_post_types_names(), + 'post', 'words', \ProgressPlanner\Admin\Page::get_params()['filter_interval'], \ProgressPlanner\Admin\Page::get_params()['filter_number'], From 20ff45e1f536c0b7503950a3a7655c84aa154658 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 27 Feb 2024 11:14:03 +0200 Subject: [PATCH 071/490] Fix saving a post --- includes/activities/class-activity-post.php | 9 +++++---- includes/class-base.php | 4 ++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/includes/activities/class-activity-post.php b/includes/activities/class-activity-post.php index 0b6a4402a..ff9f3ae78 100644 --- a/includes/activities/class-activity-post.php +++ b/includes/activities/class-activity-post.php @@ -149,16 +149,17 @@ public function transition_post_status( $new_status, $old_status, $post ) { * @return bool */ public function pre_post_update( $post_id, $post ) { + $post_array = (array) $post; // Add an update activity. $activity = new Activity(); $activity->set_category( 'post' ); $activity->set_type( 'update' ); - $activity->set_date( Date::get_datetime_from_mysql_date( $post->post_modified ) ); - $activity->set_data_id( $post->ID ); + $activity->set_date( Date::get_datetime_from_mysql_date( $post_array['post_modified'] ) ); + $activity->set_data_id( $post_id ); $activity->set_data( [ - 'post_type' => $post->post_type, - 'word_count' => static::get_word_count( $post->post_content ), + 'post_type' => $post_array['post_type'], + 'word_count' => static::get_word_count( $post_array['post_content'] ), ] ); return $activity->save(); diff --git a/includes/class-base.php b/includes/class-base.php index 6bed57846..5b04e6ebf 100644 --- a/includes/class-base.php +++ b/includes/class-base.php @@ -7,6 +7,8 @@ namespace ProgressPlanner; +use ProgressPlanner\Activities\Activity_Post; + /** * Main plugin class. */ @@ -45,6 +47,8 @@ public static function get_instance() { private function __construct() { $this->admin = new Admin(); + ( new Activity_Post() )->register_hooks(); + new Stats(); } From e072658cd3e278aa4ff2a157038771d594db9b2e Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 27 Feb 2024 11:21:52 +0200 Subject: [PATCH 072/490] Allow defining the date format for graphs --- includes/charts/class-posts.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/includes/charts/class-posts.php b/includes/charts/class-posts.php index 05d9d641a..f3ffae301 100644 --- a/includes/charts/class-posts.php +++ b/includes/charts/class-posts.php @@ -23,10 +23,11 @@ class Posts extends Chart { * @param string $interval The interval for the chart. Can be 'days', 'weeks', 'months', 'years'. * @param int $range The number of intervals to show. * @param int $offset The offset for the intervals. + * @param string $date_format The date format. * * @return void */ - public function render( $post_type = 'post', $context = 'count', $interval = 'weeks', $range = 10, $offset = 0 ) { + public function render( $post_type = 'post', $context = 'count', $interval = 'weeks', $range = 10, $offset = 0, $date_format = 'Y-m-d' ) { $range_array_end = \range( $offset, $range - 1 ); $range_array_start = \range( $offset + 1, $range ); \krsort( $range_array_start ); @@ -51,7 +52,7 @@ public function render( $post_type = 'post', $context = 'count', $interval = 'we [ 'category' => 'post', 'type' => 'publish', - 'start_date' => \DateTime::createFromFormat( 'Y-m-d', '1970-01-01' ), + 'start_date' => \DateTime::createFromFormat( $date_format, '1970-01-01' ), 'end_date' => new \DateTime( "-$range $interval" ), 'data' => [ 'post_type' => $post_type, @@ -79,7 +80,7 @@ public function render( $post_type = 'post', $context = 'count', $interval = 'we ); // TODO: Format the date depending on the user's locale. - $data['labels'][] = gmdate( 'Y-m-d', strtotime( "-$start $interval" ) ); + $data['labels'][] = gmdate( $date_format, strtotime( "-$start $interval" ) ); foreach ( $activities as $activity ) { $activity_data = $activity->get_data(); From f2f60d92c0097f20bece64e5f58964f273660ac2 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 27 Feb 2024 11:30:26 +0200 Subject: [PATCH 073/490] Remove Stat_Posts class --- includes/admin/class-page.php | 16 +++++++++----- includes/class-stats.php | 34 ----------------------------- includes/stats/class-stat-posts.php | 30 ------------------------- 3 files changed, 10 insertions(+), 70 deletions(-) delete mode 100644 includes/stats/class-stat-posts.php diff --git a/includes/admin/class-page.php b/includes/admin/class-page.php index 1d630c3ed..505015035 100644 --- a/includes/admin/class-page.php +++ b/includes/admin/class-page.php @@ -7,6 +7,8 @@ namespace ProgressPlanner\Admin; +use ProgressPlanner\Activities\Query; + /** * Admin page class. */ @@ -150,17 +152,19 @@ public function ajax_reset_stats() { * @return array The params. */ public static function get_params() { - static $stats = null; - if ( null === $stats ) { - $stats = new \ProgressPlanner\Stats\Stat_Posts(); - } return [ - 'stats' => $stats, // phpcs:ignore WordPress.Security.NonceVerification.Missing 'filter_interval' => isset( $_POST['interval'] ) ? sanitize_key( $_POST['interval'] ) : 'weeks', // phpcs:ignore WordPress.Security.NonceVerification.Missing 'filter_number' => isset( $_POST['number'] ) ? (int) $_POST['number'] : 10, - 'scan_pending' => empty( $stats->get_value() ), + 'scan_pending' => empty( + Query::get_instance()->query_activities( + [ + 'category' => 'post', + 'type' => 'publish', + ] + ) + ), ]; } } diff --git a/includes/class-stats.php b/includes/class-stats.php index 2b23c8948..71c477313 100644 --- a/includes/class-stats.php +++ b/includes/class-stats.php @@ -7,8 +7,6 @@ namespace ProgressPlanner; -use ProgressPlanner\Stats\Stat_Posts; - /** * Stats class. * @@ -23,13 +21,6 @@ class Stats { */ private $stats = []; - /** - * Constructor. - */ - public function __construct() { - $this->register_stats(); - } - /** * Add a stat to the collection. * @@ -61,29 +52,4 @@ public function get_all_stats() { public function get_stat( $id ) { return $this->stats[ $id ]; } - - /** - * Register the individual stats. - * - * @return void - */ - private function register_stats() { - $this->add_stat( 'posts', new Stat_Posts() ); - } - - /** - * Get number of activities for date range. - * - * @param \DateTime $start_date The start date. - * @param \DateTime $end_date The end date. - * @param array $args The query arguments. - * - * @return int - */ - public function get_number_of_activities( $start_date, $end_date, $args = [] ) { - $args['start_date'] = $start_date; - $args['end_date'] = $end_date; - $activities = Query::get_instance()->query_activities( $args ); - return count( $activities ); - } } diff --git a/includes/stats/class-stat-posts.php b/includes/stats/class-stat-posts.php deleted file mode 100644 index e96a5e3b6..000000000 --- a/includes/stats/class-stat-posts.php +++ /dev/null @@ -1,30 +0,0 @@ -query_activities( - [ - 'category' => 'post', - 'type' => 'publish', - ] - ); - } -} From 6261af453117a3fc81f984cafb6ea0f4efde3aec Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 27 Feb 2024 11:32:07 +0200 Subject: [PATCH 074/490] Styling graphs: Remove points --- includes/charts/class-posts.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/charts/class-posts.php b/includes/charts/class-posts.php index f3ffae301..5ee84541f 100644 --- a/includes/charts/class-posts.php +++ b/includes/charts/class-posts.php @@ -96,7 +96,7 @@ public function render( $post_type = 'post', $context = 'count', $interval = 'we md5( wp_json_encode( [ [ $post_type ], $context, $interval, $range, $offset ] ) ), 'line', $data, - [] + [ 'pointStyle' => false ] ); } } From 5fa60cfe99a2b2c7be89ec637c05615e61f04ba5 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 27 Feb 2024 11:33:22 +0200 Subject: [PATCH 075/490] Remove Stats class --- includes/class-base.php | 3 +-- includes/class-stats.php | 55 ---------------------------------------- 2 files changed, 1 insertion(+), 57 deletions(-) delete mode 100644 includes/class-stats.php diff --git a/includes/class-base.php b/includes/class-base.php index 5b04e6ebf..8c61af08f 100644 --- a/includes/class-base.php +++ b/includes/class-base.php @@ -8,6 +8,7 @@ namespace ProgressPlanner; use ProgressPlanner\Activities\Activity_Post; +use ProgressPlanner\Admin; /** * Main plugin class. @@ -48,8 +49,6 @@ private function __construct() { $this->admin = new Admin(); ( new Activity_Post() )->register_hooks(); - - new Stats(); } /** diff --git a/includes/class-stats.php b/includes/class-stats.php deleted file mode 100644 index 71c477313..000000000 --- a/includes/class-stats.php +++ /dev/null @@ -1,55 +0,0 @@ -stats[ $id ] = $stat; - } - - /** - * Get all stats. - * - * @return array - */ - public function get_all_stats() { - return $this->stats; - } - - /** - * Get an individual stat. - * - * @param string $id The ID of the stat. - * - * @return Object - */ - public function get_stat( $id ) { - return $this->stats[ $id ]; - } -} From 1da48e0ec943bdbc7c4fd5d38e6fc669548d2f0d Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 27 Feb 2024 13:53:51 +0200 Subject: [PATCH 076/490] WIP - refactoring charts --- assets/css/admin.css | 53 ++++++++++++ includes/admin/class-page.php | 40 +++++++++ includes/charts/class-posts.php | 83 ------------------ includes/class-chart.php | 100 ++++++++++++++++++++++ views/admin-page-posts-count-progress.php | 21 ----- views/admin-page-streak.php | 25 ------ views/admin-page-words-count-progress.php | 20 ----- views/admin-page.php | 10 +-- views/widget-published-posts.php | 68 +++++++++++++++ 9 files changed, 263 insertions(+), 157 deletions(-) delete mode 100644 views/admin-page-posts-count-progress.php delete mode 100644 views/admin-page-streak.php delete mode 100644 views/admin-page-words-count-progress.php create mode 100644 views/widget-published-posts.php diff --git a/assets/css/admin.css b/assets/css/admin.css index 2e230ca43..ca6ca5df0 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -1,5 +1,58 @@ +/* +Set variables. +*/ +.prpl-wrap { + --prpl-color-gray-1: #e5e7eb; + --prpl-color-gray-2: #d1d5db; + --prpl-color-gray-3: #9ca3af; + --prpl-color-gray-4: #6b7280; + --prpl-color-gray-5: #4b5563; + --prpl-color-gray-6: #374151; + + --prpl-color-accent-orange: #faa310; + --prpl-color-accent-purple: #0d6b9e; + --prpl-color-accent-green: #14b8a6; +} + +.prpl-wrap { + background: #fff; + border: 1px solid var(--prpl-color-gray-3); + border-radius: 5px; + padding: 20px; +} + #progress-planner-scan-progress progress{ width: 100%; max-width: 500px; min-height: 1px; } + +.prpl-widget-wrapper { + max-width: 300px; /* TODO: This should be dynamic based on the columns. */ + border: 1px solid var(--prpl-color-gray-3); + border-radius: 5px; + padding: 20px; +} + +.prpl-wrap .counter-big-wrapper { + background-color: var(--prpl-color-gray-1); + padding: 20px; + border-radius: 5px; + display: flex; + flex-direction: column; + align-items: center; +} + +.prpl-wrap .counter-big-number { + font-size: 4rem; + line-height: 5rem; + font-weight: 700; +} + +.prpl-wrap .counter-big-text { + font-size: 1.5rem; +} + +.prpl-wrap .prpl-widget-content p { + font-size: 1.25em; +} diff --git a/includes/admin/class-page.php b/includes/admin/class-page.php index 505015035..6bdb6ca6e 100644 --- a/includes/admin/class-page.php +++ b/includes/admin/class-page.php @@ -167,4 +167,44 @@ public static function get_params() { ), ]; } + + /** + * Get total number of published posts. + * + * @return int + */ + public static function get_posts_published_all() { + $activities = Query::get_instance()->query_activities( + [ + 'category' => 'post', + 'type' => 'publish', + 'data' => [ + 'post_type' => 'post', + ], + ] + ); + + return count( $activities ); + } + + /** + * Get number of posts published in the past week. + * + * @return int + */ + public static function get_posts_published_this_week() { + $activities = Query::get_instance()->query_activities( + [ + 'category' => 'post', + 'type' => 'publish', + 'start_date' => new \DateTime( '-7 days' ), + 'end_date' => new \DateTime( 'now' ), + 'data' => [ + 'post_type' => 'post', + ], + ] + ); + + return count( $activities ); + } } diff --git a/includes/charts/class-posts.php b/includes/charts/class-posts.php index 5ee84541f..f6180bd46 100644 --- a/includes/charts/class-posts.php +++ b/includes/charts/class-posts.php @@ -15,88 +15,5 @@ */ class Posts extends Chart { - /** - * Build a chart for the stats. - * - * @param string $post_type The post type. - * @param string $context The context for the chart. Can be 'count' or 'words'. - * @param string $interval The interval for the chart. Can be 'days', 'weeks', 'months', 'years'. - * @param int $range The number of intervals to show. - * @param int $offset The offset for the intervals. - * @param string $date_format The date format. - * - * @return void - */ - public function render( $post_type = 'post', $context = 'count', $interval = 'weeks', $range = 10, $offset = 0, $date_format = 'Y-m-d' ) { - $range_array_end = \range( $offset, $range - 1 ); - $range_array_start = \range( $offset + 1, $range ); - \krsort( $range_array_start ); - \krsort( $range_array_end ); - $range_array = \array_combine( $range_array_start, $range_array_end ); - - $data = [ - 'labels' => [], - 'datasets' => [], - ]; - $datasets = []; - $post_type_count_totals = 0; - $dataset = [ - 'label' => \get_post_type_object( $post_type )->label, - 'data' => [], - 'tension' => 0.2, - ]; - - // Calculate zero stats to be used as the baseline. - $zero_activities = Query::get_instance()->query_activities( - [ - 'category' => 'post', - 'type' => 'publish', - 'start_date' => \DateTime::createFromFormat( $date_format, '1970-01-01' ), - 'end_date' => new \DateTime( "-$range $interval" ), - 'data' => [ - 'post_type' => $post_type, - ], - ] - ); - foreach ( $zero_activities as $zero_activity ) { - $activity_data = $zero_activity->get_data(); - $post_type_count_totals += 'words' === $context - ? $activity_data['word_count'] - : 1; - } - - foreach ( $range_array as $start => $end ) { - $activities = Query::get_instance()->query_activities( - [ - 'category' => 'post', - 'type' => 'publish', - 'start_date' => new \DateTime( "-$start $interval" ), - 'end_date' => new \DateTime( "-$end $interval" ), - 'data' => [ - 'post_type' => $post_type, - ], - ] - ); - - // TODO: Format the date depending on the user's locale. - $data['labels'][] = gmdate( $date_format, strtotime( "-$start $interval" ) ); - - foreach ( $activities as $activity ) { - $activity_data = $activity->get_data(); - $post_type_count_totals += 'words' === $context - ? $activity_data['word_count'] - : 1; - } - $datasets[ $post_type ]['data'][] = $post_type_count_totals; - } - $data['datasets'] = \array_values( $datasets ); - - $this->render_chart( - md5( wp_json_encode( [ [ $post_type ], $context, $interval, $range, $offset ] ) ), - 'line', - $data, - [ 'pointStyle' => false ] - ); - } } diff --git a/includes/class-chart.php b/includes/class-chart.php index ef6774ca1..23ceb80b2 100644 --- a/includes/class-chart.php +++ b/includes/class-chart.php @@ -7,11 +7,111 @@ namespace ProgressPlanner; +use ProgressPlanner\Activities\Query; + /** * Render a chart. */ class Chart { + /** + * Build a chart for the stats. + * + * @param array $query_params The query parameters. + * string $query_params['category'] The category for the query. + * string $query_params['type'] The type for the query. + * array $query_params['data'] The data for the query. + * @param array $dates_params The dates parameters for the query. + * string $dates_params['start'] The start date for the query. + * string $dates_params['end'] The end date for the query. + * string $dates_params['interval'] The interval for the query. + * string $dates_params['format'] The format for the query. + * int $dates_params['range'] The range for the query. + * @param array $chart_params The chart parameters. + * + * @return void + */ + public function the_chart( $query_params = [], $dates_params = [], $chart_params = [] ) { + $chart_params = wp_parse_args( + $chart_params, + [ + 'type' => 'line', + 'options' => [ + 'pointStyle' => false, + 'plugins' => [ + 'legend' => [ + 'display' => false, + ], + ], + ], + ] + ); + + $range_array_end = \range( 0, $dates_params['range'] - 1 ); + $range_array_start = \range( 1, $dates_params['range'] ); + \krsort( $range_array_start ); + \krsort( $range_array_end ); + + $range_array = \array_combine( $range_array_start, $range_array_end ); + + $data = [ + 'labels' => [], + 'datasets' => [], + ]; + $datasets = [ + [ + 'label' => '', + 'data' => [], + 'tension' => 0.2, + ], + ]; + + // Calculate zero stats to be used as the baseline. + $zero_activities = Query::get_instance()->query_activities( + array_merge( + $query_params, + [ + 'start_date' => \DateTime::createFromFormat( 'Y-m-d', '1970-01-01' ), + 'end_date' => new \DateTime( "-{$dates_params['range']} {$dates_params['interval']}" ), + ] + ) + ); + $activities_count = count( $zero_activities ); + + foreach ( $range_array as $start => $end ) { + $activities = Query::get_instance()->query_activities( + array_merge( + $query_params, + [ + 'start_date' => new \DateTime( + "-$start {$dates_params['interval']}" + ), + 'end_date' => new \DateTime( + "-$end {$dates_params['interval']}" + ), + ] + ) + ); + + // TODO: Format the date depending on the user's locale. + $data['labels'][] = gmdate( + $dates_params['format'], + strtotime( "-$start {$dates_params['interval']}" ) + ); + + $activities_count += count( $activities ); + $datasets[0]['data'][] = $activities_count; + } + $data['datasets'] = $datasets; + + $this->render_chart( + md5( wp_json_encode( [ $query_params, $dates_params ] ) ), + $chart_params['type'], + $data, + $chart_params['options'] + ); + } + /** * Render the chart. * diff --git a/views/admin-page-posts-count-progress.php b/views/admin-page-posts-count-progress.php deleted file mode 100644 index e0c6448dd..000000000 --- a/views/admin-page-posts-count-progress.php +++ /dev/null @@ -1,21 +0,0 @@ -'; -echo '

'; -esc_html_e( 'Posts count progress', 'progress-planner' ); -echo '

'; - -( new \ProgressPlanner\Charts\Posts() )->render( - 'post', - 'count', - \ProgressPlanner\Admin\Page::get_params()['filter_interval'], - \ProgressPlanner\Admin\Page::get_params()['filter_number'], - 0 -); - -echo '
'; diff --git a/views/admin-page-streak.php b/views/admin-page-streak.php deleted file mode 100644 index de4d445af..000000000 --- a/views/admin-page-streak.php +++ /dev/null @@ -1,25 +0,0 @@ - 10, // Number of posts per week, targetting for 10 weeks. - 'weekly_words' => 10, // Number of words per week, targetting for 10 weeks. -]; -?> - -
- $prpl_streak_goal ) : ?> -
- get_streak( $prpl_streak_id, $prpl_streak_goal ); ?> -

-

-

- -

-
- -
diff --git a/views/admin-page-words-count-progress.php b/views/admin-page-words-count-progress.php deleted file mode 100644 index 82ed0fa5b..000000000 --- a/views/admin-page-words-count-progress.php +++ /dev/null @@ -1,20 +0,0 @@ -'; -echo '

'; -esc_html_e( 'Words count progress', 'progress-planner' ); -echo '

'; - -( new \ProgressPlanner\Charts\Posts() )->render( - 'post', - 'words', - \ProgressPlanner\Admin\Page::get_params()['filter_interval'], - \ProgressPlanner\Admin\Page::get_params()['filter_number'], - 0 -); -echo '
'; diff --git a/views/admin-page.php b/views/admin-page.php index b1cd7264b..f8463f8c7 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -6,19 +6,13 @@ */ ?> -
+

- -
- -
- - -
+
diff --git a/views/widget-published-posts.php b/views/widget-published-posts.php new file mode 100644 index 000000000..2bbeaf686 --- /dev/null +++ b/views/widget-published-posts.php @@ -0,0 +1,68 @@ + 'post', + 'type' => 'publish', + 'data' => [ + 'post_type' => 'post', + ], +]; +$prpl_last_week_posts = Admin\Page::get_posts_published_this_week(); +$prpl_all_posts_count = count( + Activities\Query::get_instance()->query_activities( $prpl_query_args ) +); + +?> +
+
+ + + + + + +
+
+

+ + + + + +

+
+
+ the_chart( + [ + 'category' => 'post', + 'type' => 'publish', + 'data' => [ + 'post_type' => 'post', + ], + ], + [ + 'start' => \DateTime::createFromFormat( 'Y-m-d', \gmdate( 'Y-m-01', \strtotime( 'now' ) ) )->modify( '-6 months' ), + 'end' => new \DateTime( 'now' ), + 'interval' => 'months', + 'range' => 6, + 'format' => 'M', + ] + ); + ?> +
+
From b72897956a38f40ac8439f8c5603ac7e353c1910 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 27 Feb 2024 15:02:36 +0200 Subject: [PATCH 077/490] more refactors & cleanup --- includes/admin/class-dashboard-widget.php | 13 ++++- includes/admin/class-page.php | 22 -------- includes/charts/class-posts.php | 19 ------- includes/class-chart.php | 66 +++++++++++------------ includes/class-date.php | 33 ++++++++++-- views/admin-page-form-filters.php | 32 ----------- views/admin-page.php | 16 +++++- views/widget-published-posts.php | 13 ++--- 8 files changed, 93 insertions(+), 121 deletions(-) delete mode 100644 includes/charts/class-posts.php delete mode 100644 views/admin-page-form-filters.php diff --git a/includes/admin/class-dashboard-widget.php b/includes/admin/class-dashboard-widget.php index ccdc9fc95..dc14276e9 100644 --- a/includes/admin/class-dashboard-widget.php +++ b/includes/admin/class-dashboard-widget.php @@ -7,6 +7,8 @@ namespace ProgressPlanner\Admin; +use ProgressPlanner\Activities\Query; + /** * Class Dashboard_Widget */ @@ -34,9 +36,18 @@ public function add_dashboard_widget() { * Render the dashboard widget. */ public function render_dashboard_widget() { + $scan_pending = empty( + Query::get_instance()->query_activities( + [ + 'category' => 'post', + 'type' => 'publish' + ] + ) + ); + ?>
- +

isset( $_POST['interval'] ) ? sanitize_key( $_POST['interval'] ) : 'weeks', - // phpcs:ignore WordPress.Security.NonceVerification.Missing - 'filter_number' => isset( $_POST['number'] ) ? (int) $_POST['number'] : 10, - 'scan_pending' => empty( - Query::get_instance()->query_activities( - [ - 'category' => 'post', - 'type' => 'publish', - ] - ) - ), - ]; - } - /** * Get total number of published posts. * diff --git a/includes/charts/class-posts.php b/includes/charts/class-posts.php deleted file mode 100644 index f6180bd46..000000000 --- a/includes/charts/class-posts.php +++ /dev/null @@ -1,19 +0,0 @@ - [], @@ -67,37 +67,31 @@ public function the_chart( $query_params = [], $dates_params = [], $chart_params ]; // Calculate zero stats to be used as the baseline. - $zero_activities = Query::get_instance()->query_activities( - array_merge( - $query_params, - [ - 'start_date' => \DateTime::createFromFormat( 'Y-m-d', '1970-01-01' ), - 'end_date' => new \DateTime( "-{$dates_params['range']} {$dates_params['interval']}" ), - ] + $activities_count = count( + Query::get_instance()->query_activities( + array_merge( + $query_params, + [ + 'start_date' => Query::get_instance()->get_oldest_activity()->get_date(), + 'end_date' => $periods[0]['dates'][0]->modify( '-1 day' ), + ] + ) ) ); - $activities_count = count( $zero_activities ); - foreach ( $range_array as $start => $end ) { + foreach ( $periods as $period ) { $activities = Query::get_instance()->query_activities( array_merge( $query_params, [ - 'start_date' => new \DateTime( - "-$start {$dates_params['interval']}" - ), - 'end_date' => new \DateTime( - "-$end {$dates_params['interval']}" - ), + 'start_date' => $period['dates'][0], + 'end_date' => end( $period['dates'] ), ] ) ); // TODO: Format the date depending on the user's locale. - $data['labels'][] = gmdate( - $dates_params['format'], - strtotime( "-$start {$dates_params['interval']}" ) - ); + $data['labels'][] = $period['start']->format( $dates_params['format'] ); $activities_count += count( $activities ); $datasets[0]['data'][] = $activities_count; diff --git a/includes/class-date.php b/includes/class-date.php index e8b3150a7..ca65fb114 100644 --- a/includes/class-date.php +++ b/includes/class-date.php @@ -24,7 +24,7 @@ class Date { * 'dates' => [ 'Ymd', 'Ymd', ... ], * ]. */ - public function get_range( $start, $end ) { + public static function get_range( $start, $end ) { return [ 'start' => $start, 'end' => $end, @@ -41,7 +41,7 @@ public function get_range( $start, $end ) { * * @return array */ - public function get_periods( $start, $end, $frequency ) { + public static function get_periods( $start, $end, $frequency ) { $end = $end->modify( '+1 day' ); switch ( $frequency ) { @@ -66,9 +66,12 @@ public function get_periods( $start, $end, $frequency ) { $date_ranges = []; foreach ( $period as $key => $date ) { if ( isset( $period[ $key + 1 ] ) ) { - $date_ranges[] = $this->get_range( $date, $period[ $key + 1 ] ); + $date_ranges[] = static::get_range( $date, $period[ $key + 1 ] ); } } + if ( $end->format( 'z' ) !== end( $date_ranges )['end']->format( 'z' ) ) { + $date_ranges[] = static::get_range( end( $date_ranges )['end'], $end ); + } return $date_ranges; } @@ -83,4 +86,28 @@ public function get_periods( $start, $end, $frequency ) { public static function get_datetime_from_mysql_date( $date ) { return \DateTime::createFromFormat( 'U', (int) mysql2date( 'U', $date ) ); } + + /** + * Get start of week from a date. + * + * @param \DateTime $date The date. + * + * @return \DateTime + */ + public static function get_start_of_week( $date ) { + $day_of_week = (int) $date->format( 'N' ); + $day_of_week = $day_of_week === 7 ? 0 : $day_of_week; + return $date->modify( "-{$day_of_week} days" ); + } + + /** + * Get start of month from a date. + * + * @param \DateTime $date The date. + * + * @return \DateTime + */ + public static function get_start_of_month( $date ) { + return $date->modify( 'first day of this month' ); + } } diff --git a/views/admin-page-form-filters.php b/views/admin-page-form-filters.php deleted file mode 100644 index cc7bd724f..000000000 --- a/views/admin-page-form-filters.php +++ /dev/null @@ -1,32 +0,0 @@ - __( 'Days', 'progress-planner' ), - 'weeks' => __( 'Weeks', 'progress-planner' ), - 'months' => __( 'Months', 'progress-planner' ), -]; - -?> -

-

-
- - - -
-
diff --git a/views/admin-page.php b/views/admin-page.php index f8463f8c7..ca3a7aedf 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -5,11 +5,23 @@ * @package ProgressPlanner */ +namespace ProgressPlanner; + +use ProgressPlanner\Activities\Query; + +$prpl_scan_pending = empty( + Query::get_instance()->query_activities( + [ + 'category' => 'post', + 'type' => 'publish' + ] + ) +); ?>
-

+

- + diff --git a/views/widget-published-posts.php b/views/widget-published-posts.php index 2bbeaf686..cec056266 100644 --- a/views/widget-published-posts.php +++ b/views/widget-published-posts.php @@ -14,6 +14,7 @@ 'post_type' => 'post', ], ]; + $prpl_last_week_posts = Admin\Page::get_posts_published_this_week(); $prpl_all_posts_count = count( Activities\Query::get_instance()->query_activities( $prpl_query_args ) @@ -47,7 +48,7 @@
the_chart( + ( new Chart() )->the_chart( [ 'category' => 'post', 'type' => 'publish', @@ -56,11 +57,11 @@ ], ], [ - 'start' => \DateTime::createFromFormat( 'Y-m-d', \gmdate( 'Y-m-01', \strtotime( 'now' ) ) )->modify( '-6 months' ), - 'end' => new \DateTime( 'now' ), - 'interval' => 'months', - 'range' => 6, - 'format' => 'M', + 'start' => \DateTime::createFromFormat( 'Y-m-d', \gmdate( 'Y-m-01', \strtotime( 'now' ) ) )->modify( '-5 months' ), + 'end' => new \DateTime( 'now' ), + 'frequency' => 'monthly', + 'range' => 6, + 'format' => 'M', ] ); ?> From 6e8385a926b857d71405fcc76320569238ea14f6 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 27 Feb 2024 15:31:01 +0200 Subject: [PATCH 078/490] Add a progress_planner function in root, and a get_query method in Base --- includes/activities/class-activity-post.php | 7 +++---- includes/activities/class-activity.php | 8 ++++---- includes/admin/class-dashboard-widget.php | 4 +--- includes/admin/class-page.php | 6 ++---- includes/class-base.php | 10 ++++++++++ includes/class-chart.php | 9 ++++----- includes/class-streaks.php | 9 ++++----- includes/scan/class-posts.php | 3 +-- progress-planner.php | 11 +++++++++-- views/admin-page-debug.php | 2 +- views/admin-page.php | 4 +--- views/widget-published-posts.php | 2 +- 12 files changed, 41 insertions(+), 34 deletions(-) diff --git a/includes/activities/class-activity-post.php b/includes/activities/class-activity-post.php index ff9f3ae78..12fed6395 100644 --- a/includes/activities/class-activity-post.php +++ b/includes/activities/class-activity-post.php @@ -7,7 +7,6 @@ namespace ProgressPlanner\Activities; -use ProgressPlanner\Activities\Query; use ProgressPlanner\Activities\Activity; use ProgressPlanner\Date; @@ -95,7 +94,7 @@ public function transition_post_status( $new_status, $old_status, $post ) { // If the post is published, check if it was previously published, // and if so, delete the old activity and create a new one. if ( 'publish' !== $old_status && 'publish' === $new_status ) { - $old_publish_activities = Query::get_instance()->query_activities( + $old_publish_activities = \progress_planner()->get_query()->query_activities( [ 'category' => 'post', 'type' => 'publish', @@ -215,7 +214,7 @@ public function delete_post( $post_id ) { } // Update existing activities, and remove the words count. - $activities = Query::get_instance()->query_activities( + $activities = \progress_planner()->get_query()->query_activities( [ 'category' => 'post', 'data_id' => $post->ID, @@ -226,7 +225,7 @@ public function delete_post( $post_id ) { $activity->set_data( [ 'post_type' => $post->post_type ] ); $activity->save(); } - Query::get_instance()->delete_activities( $activities ); + \progress_planner()->get_query()->delete_activities( $activities ); } $activity = new Activity(); diff --git a/includes/activities/class-activity.php b/includes/activities/class-activity.php index 5f0fa623e..b850df9dd 100644 --- a/includes/activities/class-activity.php +++ b/includes/activities/class-activity.php @@ -172,7 +172,7 @@ public function get_data() { * @return void */ public function save() { - $existing = Query::get_instance()->query_activities( + $existing = \progress_planner()->get_query()->query_activities( [ 'category' => $this->category, 'type' => $this->type, @@ -180,9 +180,9 @@ public function save() { ] ); if ( ! empty( $existing ) ) { - Query::get_instance()->update_activity( $existing[0]->id, $this ); + \progress_planner()->get_query()->update_activity( $existing[0]->id, $this ); } else { - Query::get_instance()->insert_activity( $this ); + \progress_planner()->get_query()->insert_activity( $this ); } } @@ -192,6 +192,6 @@ public function save() { * @return void */ public function delete() { - Query::get_instance()->delete_activity( $this ); + \progress_planner()->get_query()->delete_activity( $this ); } } diff --git a/includes/admin/class-dashboard-widget.php b/includes/admin/class-dashboard-widget.php index dc14276e9..52974123a 100644 --- a/includes/admin/class-dashboard-widget.php +++ b/includes/admin/class-dashboard-widget.php @@ -7,8 +7,6 @@ namespace ProgressPlanner\Admin; -use ProgressPlanner\Activities\Query; - /** * Class Dashboard_Widget */ @@ -37,7 +35,7 @@ public function add_dashboard_widget() { */ public function render_dashboard_widget() { $scan_pending = empty( - Query::get_instance()->query_activities( + \progress_planner()->get_query()->query_activities( [ 'category' => 'post', 'type' => 'publish' diff --git a/includes/admin/class-page.php b/includes/admin/class-page.php index 52366fc79..6627b7bf6 100644 --- a/includes/admin/class-page.php +++ b/includes/admin/class-page.php @@ -7,8 +7,6 @@ namespace ProgressPlanner\Admin; -use ProgressPlanner\Activities\Query; - /** * Admin page class. */ @@ -152,7 +150,7 @@ public function ajax_reset_stats() { * @return int */ public static function get_posts_published_all() { - $activities = Query::get_instance()->query_activities( + $activities = \progress_planner()->get_query()->query_activities( [ 'category' => 'post', 'type' => 'publish', @@ -171,7 +169,7 @@ public static function get_posts_published_all() { * @return int */ public static function get_posts_published_this_week() { - $activities = Query::get_instance()->query_activities( + $activities = \progress_planner()->get_query()->query_activities( [ 'category' => 'post', 'type' => 'publish', diff --git a/includes/class-base.php b/includes/class-base.php index 8c61af08f..93fe0bdd2 100644 --- a/includes/class-base.php +++ b/includes/class-base.php @@ -7,6 +7,7 @@ namespace ProgressPlanner; +use ProgressPlanner\Activities\Query; use ProgressPlanner\Activities\Activity_Post; use ProgressPlanner\Admin; @@ -59,4 +60,13 @@ private function __construct() { public function get_admin() { return $this->admin; } + + /** + * Get the query object. + * + * @return \ProgressPlanner\Activities\Query + */ + public function get_query() { + return Query::get_instance(); + } } diff --git a/includes/class-chart.php b/includes/class-chart.php index fb0f68931..2d3ae5202 100644 --- a/includes/class-chart.php +++ b/includes/class-chart.php @@ -7,7 +7,6 @@ namespace ProgressPlanner; -use ProgressPlanner\Activities\Query; use ProgressPlanner\Date; /** @@ -68,11 +67,11 @@ public function the_chart( $query_params = [], $dates_params = [], $chart_params // Calculate zero stats to be used as the baseline. $activities_count = count( - Query::get_instance()->query_activities( + \progress_planner()->get_query()->query_activities( array_merge( $query_params, [ - 'start_date' => Query::get_instance()->get_oldest_activity()->get_date(), + 'start_date' => \progress_planner()->get_query()->get_oldest_activity()->get_date(), 'end_date' => $periods[0]['dates'][0]->modify( '-1 day' ), ] ) @@ -80,7 +79,7 @@ public function the_chart( $query_params = [], $dates_params = [], $chart_params ); foreach ( $periods as $period ) { - $activities = Query::get_instance()->query_activities( + $activities = \progress_planner()->get_query()->query_activities( array_merge( $query_params, [ @@ -91,7 +90,7 @@ public function the_chart( $query_params = [], $dates_params = [], $chart_params ); // TODO: Format the date depending on the user's locale. - $data['labels'][] = $period['start']->format( $dates_params['format'] ); + $data['labels'][] = $period['dates'][0]->format( $dates_params['format'] ); $activities_count += count( $activities ); $datasets[0]['data'][] = $activities_count; diff --git a/includes/class-streaks.php b/includes/class-streaks.php index e38953426..4bed156f0 100644 --- a/includes/class-streaks.php +++ b/includes/class-streaks.php @@ -9,7 +9,6 @@ use ProgressPlanner\Goals\Goal_Posts; use ProgressPlanner\Goals\Goal_Recurring; -use ProgressPlanner\Activities\Query; /** * Streaks class. @@ -123,7 +122,7 @@ private function get_weekly_post_goal() { 'priority' => 'low', 'evaluate' => function ( $goal_object ) { return (bool) count( - Query::get_instance()->query_activities( + \progress_planner()->get_query()->query_activities( [ 'category' => 'post', 'type' => 'publish', @@ -139,7 +138,7 @@ private function get_weekly_post_goal() { ] ), 'weekly', - Query::get_instance()->get_oldest_activity()->get_date(), // Beginning of the stats. + \progress_planner()->get_query()->get_oldest_activity()->get_date(), // Beginning of the stats. new \DateTime( 'now' ) // Today. ); } @@ -159,7 +158,7 @@ private function get_weekly_words_goal() { 'status' => 'active', 'priority' => 'low', 'evaluate' => function ( $goal_object ) { - $activities = Query::get_instance()->query_activities( + $activities = \progress_planner()->get_query()->query_activities( [ 'category' => 'post', 'type' => 'publish', @@ -179,7 +178,7 @@ private function get_weekly_words_goal() { ] ), 'weekly', - Query::get_instance()->get_oldest_activity()->get_date(), // Beginning of the stats. + \progress_planner()->get_query()->get_oldest_activity()->get_date(), // Beginning of the stats. new \DateTime( 'now' ) // Today. ); } diff --git a/includes/scan/class-posts.php b/includes/scan/class-posts.php index c280f05d2..3648c13d6 100644 --- a/includes/scan/class-posts.php +++ b/includes/scan/class-posts.php @@ -10,7 +10,6 @@ use ProgressPlanner\Activities\Activity; use ProgressPlanner\Date; use ProgressPlanner\Activities\Activity_Post; -use ProgressPlanner\Activities\Query; /** * Scan existing posts and populate the options. @@ -114,7 +113,7 @@ public static function update_stats() { * @return void */ public static function reset_stats() { - Query::get_instance()->delete_category_activities( 'post' ); + \progress_planner()->get_query()->delete_category_activities( 'post' ); \delete_option( static::LAST_SCANNED_PAGE_OPTION ); } } diff --git a/progress-planner.php b/progress-planner.php index dc4a2e116..2ad632391 100644 --- a/progress-planner.php +++ b/progress-planner.php @@ -10,6 +10,13 @@ require_once PROGRESS_PLANNER_DIR . '/includes/autoload.php'; -\ProgressPlanner\Base::get_instance(); +/** + * Get the progress planner instance. + * + * @return \ProgressPlanner\Base + */ +function progress_planner() { + return \ProgressPlanner\Base::get_instance(); +} -$prpl_storage = \ProgressPlanner\Activities\Query::get_instance(); +progress_planner(); diff --git a/views/admin-page-debug.php b/views/admin-page-debug.php index 391c9681d..b01d8350c 100644 --- a/views/admin-page-debug.php +++ b/views/admin-page-debug.php @@ -16,7 +16,7 @@
 		query_activities( [] ) );
+		print_r( \progress_planner()->get_query()->query_activities( [] ) );
 		?>
 	
diff --git a/views/admin-page.php b/views/admin-page.php index ca3a7aedf..86880b0af 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -7,10 +7,8 @@ namespace ProgressPlanner; -use ProgressPlanner\Activities\Query; - $prpl_scan_pending = empty( - Query::get_instance()->query_activities( + \progress_planner()->get_query()->query_activities( [ 'category' => 'post', 'type' => 'publish' diff --git a/views/widget-published-posts.php b/views/widget-published-posts.php index cec056266..4234287fe 100644 --- a/views/widget-published-posts.php +++ b/views/widget-published-posts.php @@ -17,7 +17,7 @@ $prpl_last_week_posts = Admin\Page::get_posts_published_this_week(); $prpl_all_posts_count = count( - Activities\Query::get_instance()->query_activities( $prpl_query_args ) + \progress_planner()->get_query()->query_activities( $prpl_query_args ) ); ?> From b8b5de70c199e09519d6f9e33a736ae990396616 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 28 Feb 2024 11:22:22 +0200 Subject: [PATCH 079/490] Improve queries --- includes/activities/class-query.php | 61 +++++++++++++++++------------ 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/includes/activities/class-query.php b/includes/activities/class-query.php index 39fad776c..65cd7031d 100644 --- a/includes/activities/class-query.php +++ b/includes/activities/class-query.php @@ -114,33 +114,44 @@ public function query_activities( $args ) { $args = \wp_parse_args( $args, $defaults ); - // If start and end dates are defined, then get activities by date. - if ( $args['start_date'] && $args['end_date'] ) { - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching - $results = $wpdb->get_results( - $wpdb->prepare( - 'SELECT * FROM %i WHERE date >= %s AND date <= %s AND category LIKE %s AND type LIKE %s AND data_id LIKE %s', - $wpdb->prefix . static::TABLE_NAME, - $args['start_date']->format( 'Y-m-d' ), - $args['end_date']->format( 'Y-m-d' ), - $args['category'], - $args['type'], - $args['data_id'] - ) - ); - } else { - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching - $results = $wpdb->get_results( - $wpdb->prepare( - 'SELECT * FROM %i WHERE category LIKE %s AND type LIKE %s AND data_id LIKE %s', - $wpdb->prefix . static::TABLE_NAME, - $args['category'], - $args['type'], - $args['data_id'] - ) - ); + $where_args = []; + $prepare_args = []; + if ( $args['start_date'] ) { + $where_args[] = 'date >= %s'; + $prepare_args[] = $args['start_date']->format( 'Y-m-d H:i:s' ); + } + if ( $args['end_date'] ) { + $where_args[] = 'date <= %s'; + $prepare_args[] = $args['end_date']->format( 'Y-m-d H:i:s' ); + } + if ( $args['category'] !== '%' ) { + $where_args[] = 'category = %s'; + $prepare_args[] = $args['category']; + } + if ( $args['type'] !== '%' ) { + $where_args[] = 'type = %s'; + $prepare_args[] = $args['type']; + } + if ( $args['data_id'] !== '%' ) { + $where_args[] = 'data_id = %s'; + $prepare_args[] = $args['data_id']; } + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching + $results = $wpdb->get_results( + // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber -- This is a false positive. + $wpdb->prepare( + sprintf( + 'SELECT * FROM %%i WHERE %s', + \implode( ' AND ', $where_args ) + ), + array_merge( + [ $wpdb->prefix . static::TABLE_NAME ], + $prepare_args + ) + ) + ); + $activities = $this->get_activities_from_results( $results ); if ( isset( $args['data'] ) && ! empty( $args['data'] ) ) { From 34cd2891590445d94fbb7a06e53508764eed44d1 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 28 Feb 2024 11:42:09 +0200 Subject: [PATCH 080/490] bugfix for query --- includes/activities/class-query.php | 31 +++++++++++++++++------------ 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/includes/activities/class-query.php b/includes/activities/class-query.php index 65cd7031d..a121d2197 100644 --- a/includes/activities/class-query.php +++ b/includes/activities/class-query.php @@ -137,20 +137,25 @@ public function query_activities( $args ) { $prepare_args[] = $args['data_id']; } - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching - $results = $wpdb->get_results( - // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber -- This is a false positive. - $wpdb->prepare( - sprintf( - 'SELECT * FROM %%i WHERE %s', - \implode( ' AND ', $where_args ) - ), - array_merge( - [ $wpdb->prefix . static::TABLE_NAME ], - $prepare_args - ) + $results = ( empty( $where_args ) ) + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching + ? $wpdb->get_results( + $wpdb->prepare( 'SELECT * FROM %i', $wpdb->prefix . static::TABLE_NAME ) ) - ); + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching + : $wpdb->get_results( + // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber -- This is a false positive. + $wpdb->prepare( + sprintf( + 'SELECT * FROM %%i WHERE %s', + \implode( ' AND ', $where_args ) + ), + array_merge( + [ $wpdb->prefix . static::TABLE_NAME ], + $prepare_args + ) + ) + ); $activities = $this->get_activities_from_results( $results ); From bf768e7f2d2e41b978cb073162996f08f4760e8b Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 28 Feb 2024 13:47:14 +0200 Subject: [PATCH 081/490] scanner bugfixes --- assets/js/admin.js | 25 +---------- includes/activities/class-activity-post.php | 4 -- includes/activities/class-query.php | 48 +++++++++++++-------- includes/admin/class-dashboard-widget.php | 2 +- includes/scan/class-posts.php | 27 ++++-------- views/admin-page.php | 2 +- 6 files changed, 42 insertions(+), 66 deletions(-) diff --git a/assets/js/admin.js b/assets/js/admin.js index 9fb5cf69d..9c8fe7a42 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -68,29 +68,7 @@ const progressPlannerTriggerScan = () => { return; } - // Wait half a second and re-trigger. - setTimeout( () => { - progressPlannerTriggerScan(); - }, 500 ); - }; - - /** - * The action to run on a failed AJAX request. - * This function should re-trigger the scan if necessary. - * If the response contains a `progress` property, the successAction should be run instead. - * - * @param {Object} response The response from the server. - */ - const failAction = ( response ) => { - if ( response && response.data && response.data.progress ) { - successAction( response ); - return; - } - - // Wait 2 seconds and re-trigger. - setTimeout( () => { - progressPlannerTriggerScan(); - }, 1000 ); + progressPlannerTriggerScan(); }; /** @@ -103,7 +81,6 @@ const progressPlannerTriggerScan = () => { _ajax_nonce: progressPlanner.nonce, }, successAction: successAction, - failAction: failAction, } ); }; diff --git a/includes/activities/class-activity-post.php b/includes/activities/class-activity-post.php index 12fed6395..3f9e94060 100644 --- a/includes/activities/class-activity-post.php +++ b/includes/activities/class-activity-post.php @@ -221,10 +221,6 @@ public function delete_post( $post_id ) { ] ); if ( ! empty( $activities ) ) { - foreach ( $activities as $activity ) { - $activity->set_data( [ 'post_type' => $post->post_type ] ); - $activity->save(); - } \progress_planner()->get_query()->delete_activities( $activities ); } diff --git a/includes/activities/class-query.php b/includes/activities/class-query.php index a121d2197..d9874cfd0 100644 --- a/includes/activities/class-query.php +++ b/includes/activities/class-query.php @@ -97,42 +97,43 @@ private function create_activities_table() { /** * Query the database for activities. * - * @param array $args The arguments for the query. + * @param array $args The arguments for the query. + * @param string $return_type The type of the return value. Can be "RAW" or "ACTIVITIES". * * @return \ProgressPlanner\Activities\Activity[] The activities. */ - public function query_activities( $args ) { + public function query_activities( $args, $return_type = 'ACTIVITIES' ) { global $wpdb; $defaults = [ 'start_date' => null, 'end_date' => null, - 'category' => '%', - 'type' => '%', - 'data_id' => '%', + 'category' => null, + 'type' => null, + 'data_id' => null, ]; $args = \wp_parse_args( $args, $defaults ); $where_args = []; $prepare_args = []; - if ( $args['start_date'] ) { + if ( $args['start_date'] !== null ) { $where_args[] = 'date >= %s'; $prepare_args[] = $args['start_date']->format( 'Y-m-d H:i:s' ); } - if ( $args['end_date'] ) { + if ( $args['end_date'] !== null ) { $where_args[] = 'date <= %s'; $prepare_args[] = $args['end_date']->format( 'Y-m-d H:i:s' ); } - if ( $args['category'] !== '%' ) { + if ( $args['category'] !== null ) { $where_args[] = 'category = %s'; $prepare_args[] = $args['category']; } - if ( $args['type'] !== '%' ) { + if ( $args['type'] !== null ) { $where_args[] = 'type = %s'; $prepare_args[] = $args['type']; } - if ( $args['data_id'] !== '%' ) { + if ( $args['data_id'] !== null ) { $where_args[] = 'data_id = %s'; $prepare_args[] = $args['data_id']; } @@ -157,20 +158,20 @@ public function query_activities( $args ) { ) ); - $activities = $this->get_activities_from_results( $results ); - if ( isset( $args['data'] ) && ! empty( $args['data'] ) ) { - foreach ( $activities as $key => $activity ) { - $data = $activity->get_data(); + foreach ( $results as $key => $activity ) { + $data = \json_decode( $activity->data, true ); foreach ( $args['data'] as $data_key => $data_value ) { if ( ! isset( $data[ $data_key ] ) || $data[ $data_key ] !== $data_value ) { - unset( $activities[ $key ] ); + unset( $results[ $key ] ); } } } - $activities = \array_values( $activities ); + $results = \array_values( $results ); } - return $activities; + return 'RAW' === $return_type + ? $results + : $this->get_activities_from_results( $results ); } /** @@ -308,12 +309,23 @@ public function delete_activities( $activities ) { * @return void */ public function delete_activity( $activity ) { + $this->delete_activity_by_id( $activity->get_id() ); + } + + /** + * Delete activitiy by ID. + * + * @param int $id The ID of the activity to delete. + * + * @return void + */ + public function delete_activity_by_id( $id ) { global $wpdb; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery $wpdb->delete( $wpdb->prefix . static::TABLE_NAME, - [ 'id' => $activity->get_id() ], + [ 'id' => $id ], [ '%d' ] ); } diff --git a/includes/admin/class-dashboard-widget.php b/includes/admin/class-dashboard-widget.php index 52974123a..4500a6cda 100644 --- a/includes/admin/class-dashboard-widget.php +++ b/includes/admin/class-dashboard-widget.php @@ -38,7 +38,7 @@ public function render_dashboard_widget() { \progress_planner()->get_query()->query_activities( [ 'category' => 'post', - 'type' => 'publish' + 'type' => 'publish', ] ) ); diff --git a/includes/scan/class-posts.php b/includes/scan/class-posts.php index 3648c13d6..c3db298bf 100644 --- a/includes/scan/class-posts.php +++ b/includes/scan/class-posts.php @@ -21,7 +21,7 @@ class Posts { * * @var int */ - const SCAN_POSTS_PER_PAGE = 50; + const SCAN_POSTS_PER_PAGE = 30; /** * The option used to store the last scanned page. @@ -59,20 +59,21 @@ public static function update_stats() { 'posts_per_page' => static::SCAN_POSTS_PER_PAGE, 'paged' => $current_page, 'post_type' => Activity_Post::get_post_types_names(), - 'post_status' => 'any', + 'post_status' => 'publish', ] ); if ( ! $posts ) { \delete_option( static::LAST_SCANNED_PAGE_OPTION ); return [ - 'lastScannedPage' => $last_page, + 'lastScannedPage' => $current_page, 'lastPage' => $total_pages, 'progress' => 100, ]; } // Loop through the posts and update the stats. + $activities = []; foreach ( $posts as $post ) { $activity = new Activity(); $activity->set_category( 'post' ); @@ -83,25 +84,15 @@ public static function update_stats() { 'word_count' => Activity_Post::get_word_count( $post->post_content ), ] ); - - switch ( $post->post_status ) { - case 'publish': - $activity->set_type( 'publish' ); - $activity->set_date( Date::get_datetime_from_mysql_date( $post->post_date ) ); - break; - - default: - $activity->set_type( 'update' ); - $activity->set_date( Date::get_datetime_from_mysql_date( $post->post_modified ) ); - } - - $activity->save(); + $activity->set_type( 'publish' ); + $activity->set_date( Date::get_datetime_from_mysql_date( $post->post_date ) ); + $activities[ $post->ID ] = $activity; } - + \progress_planner()->get_query()->insert_activities( $activities ); \update_option( static::LAST_SCANNED_PAGE_OPTION, $current_page ); return [ - 'lastScannedPage' => $last_page, + 'lastScannedPage' => $current_page, 'lastPage' => $total_pages, 'progress' => round( ( $current_page / max( 1, $total_pages ) ) * 100 ), ]; diff --git a/views/admin-page.php b/views/admin-page.php index 86880b0af..86303be40 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -11,7 +11,7 @@ \progress_planner()->get_query()->query_activities( [ 'category' => 'post', - 'type' => 'publish' + 'type' => 'publish', ] ) ); From beb6ac36209fb3e7f7e5219453ba59ad0f605673 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 28 Feb 2024 13:48:54 +0200 Subject: [PATCH 082/490] Activity bugfix --- includes/activities/class-activity.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/activities/class-activity.php b/includes/activities/class-activity.php index b850df9dd..8f1435d94 100644 --- a/includes/activities/class-activity.php +++ b/includes/activities/class-activity.php @@ -177,7 +177,8 @@ public function save() { 'category' => $this->category, 'type' => $this->type, 'data_id' => $this->data_id, - ] + ], + 'RAW' ); if ( ! empty( $existing ) ) { \progress_planner()->get_query()->update_activity( $existing[0]->id, $this ); From 11778f980d9cd6cba023bbffbfb6c698f08280e3 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 28 Feb 2024 15:52:33 +0200 Subject: [PATCH 083/490] jigsaw falling into place --- assets/css/admin.css | 15 +++- includes/activities/class-activity.php | 11 ++- includes/admin/class-page.php | 6 +- includes/class-chart.php | 116 ++++++++++++++++--------- includes/class-streaks.php | 2 +- views/admin-page.php | 7 +- views/widget-activity-scores.php | 54 ++++++++++++ views/widget-published-pages.php | 73 ++++++++++++++++ views/widget-published-posts.php | 30 ++++--- views/widget-published-words.php | 91 +++++++++++++++++++ 10 files changed, 341 insertions(+), 64 deletions(-) create mode 100644 views/widget-activity-scores.php create mode 100644 views/widget-published-pages.php create mode 100644 views/widget-published-words.php diff --git a/assets/css/admin.css b/assets/css/admin.css index ca6ca5df0..399fcd9c4 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -27,11 +27,19 @@ Set variables. min-height: 1px; } +.prpl-widgets-container { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); + grid-gap: 20px; +} + .prpl-widget-wrapper { - max-width: 300px; /* TODO: This should be dynamic based on the columns. */ border: 1px solid var(--prpl-color-gray-3); border-radius: 5px; padding: 20px; + max-height: 500px; + display: flex; + flex-direction: column; } .prpl-wrap .counter-big-wrapper { @@ -56,3 +64,8 @@ Set variables. .prpl-wrap .prpl-widget-content p { font-size: 1.25em; } + +.prpl-graph-wrapper { + position: relative; + height: 100%; +} diff --git a/includes/activities/class-activity.php b/includes/activities/class-activity.php index 8f1435d94..38cd58f33 100644 --- a/includes/activities/class-activity.php +++ b/includes/activities/class-activity.php @@ -160,10 +160,15 @@ public function set_data( array $data ) { /** * Get the data of the activity. * - * @return array + * @param string|null $key The key of the data to get. If null, then all data is returned. + * + * @return mixed */ - public function get_data() { - return $this->data; + public function get_data( $key = null ) { + if ( null === $key ) { + return $this->data; + } + return isset( $this->data[ $key ] ) ? $this->data[ $key ] : null; } /** diff --git a/includes/admin/class-page.php b/includes/admin/class-page.php index 6627b7bf6..e6071c36a 100644 --- a/includes/admin/class-page.php +++ b/includes/admin/class-page.php @@ -166,9 +166,11 @@ public static function get_posts_published_all() { /** * Get number of posts published in the past week. * + * @param string $post_type The post type. + * * @return int */ - public static function get_posts_published_this_week() { + public static function get_posts_published_this_week( $post_type ) { $activities = \progress_planner()->get_query()->query_activities( [ 'category' => 'post', @@ -176,7 +178,7 @@ public static function get_posts_published_this_week() { 'start_date' => new \DateTime( '-7 days' ), 'end_date' => new \DateTime( 'now' ), 'data' => [ - 'post_type' => 'post', + 'post_type' => $post_type, ], ] ); diff --git a/includes/class-chart.php b/includes/class-chart.php index 2d3ae5202..c91dd7357 100644 --- a/includes/class-chart.php +++ b/includes/class-chart.php @@ -17,28 +17,52 @@ class Chart { /** * Build a chart for the stats. * - * @param array $query_params The query parameters. - * string $query_params['category'] The category for the query. - * string $query_params['type'] The type for the query. - * array $query_params['data'] The data for the query. - * @param array $dates_params The dates parameters for the query. - * string $dates_params['start'] The start date for the chart. - * string $dates_params['end'] The end date for the chart. - * string $dates_params['frequency'] The frequency for the chart. - * string $dates_params['format'] The format for the chart. - * int $dates_params['range'] The range for the chart. - * @param array $chart_params The chart parameters. + * @param array $args The arguments for the chart. + * ['query_params'] The query parameters. + * See Query::query_activities for the available parameters. + * + * ['dates_params'] The dates parameters for the query. + * ['start'] The start date for the chart. + * ['end'] The end date for the chart. + * ['frequency'] The frequency for the chart nodes. + * ['format'] The format for the label + * + * ['chart_params'] The chart parameters. + * + * [additive] Whether to add the stats for next node to the previous one. * * @return void */ - public function the_chart( $query_params = [], $dates_params = [], $chart_params = [] ) { - $chart_params = wp_parse_args( - $chart_params, + public function the_chart( $args = [] ) { + $args = wp_parse_args( + $args, + [ + 'query_params' => [], + 'dates_params' => [], + 'chart_params' => [], + 'additive' => true, + 'colors' => [ + 'background' => function () { + return '#534786'; + }, + 'border' => function () { + return '#534786'; + }, + ], + 'count_callback' => function ( $activities ) { + return count( $activities ); + }, + ] + ); + $args['chart_params'] = wp_parse_args( + $args['chart_params'], [ 'type' => 'line', 'options' => [ - 'pointStyle' => false, - 'plugins' => [ + 'responsive' => true, + 'maintainAspectRatio' => false, + 'pointStyle' => false, + 'plugins' => [ 'legend' => [ 'display' => false, ], @@ -48,9 +72,9 @@ public function the_chart( $query_params = [], $dates_params = [], $chart_params ); $periods = Date::get_periods( - $dates_params['start'], - $dates_params['end'], - 'monthly' + $args['dates_params']['start'], + $args['dates_params']['end'], + $args['dates_params']['frequency'] ); $data = [ @@ -59,29 +83,32 @@ public function the_chart( $query_params = [], $dates_params = [], $chart_params ]; $datasets = [ [ - 'label' => '', - 'data' => [], - 'tension' => 0.2, + 'label' => '', + 'data' => [], + 'tension' => 0.2, + 'backgroundColor' => [], + 'borderColor' => [], ], ]; // Calculate zero stats to be used as the baseline. - $activities_count = count( - \progress_planner()->get_query()->query_activities( - array_merge( - $query_params, - [ - 'start_date' => \progress_planner()->get_query()->get_oldest_activity()->get_date(), - 'end_date' => $periods[0]['dates'][0]->modify( '-1 day' ), - ] + $activities_count = $args['additive'] + ? $args['count_callback']( + \progress_planner()->get_query()->query_activities( + array_merge( + $args['query_params'], + [ + 'start_date' => \progress_planner()->get_query()->get_oldest_activity()->get_date(), + 'end_date' => $periods[0]['dates'][0]->modify( '-1 day' ), + ] + ) ) - ) - ); + ) : 0; foreach ( $periods as $period ) { $activities = \progress_planner()->get_query()->query_activities( array_merge( - $query_params, + $args['query_params'], [ 'start_date' => $period['dates'][0], 'end_date' => end( $period['dates'] ), @@ -89,19 +116,22 @@ public function the_chart( $query_params = [], $dates_params = [], $chart_params ) ); - // TODO: Format the date depending on the user's locale. - $data['labels'][] = $period['dates'][0]->format( $dates_params['format'] ); + $data['labels'][] = $period['dates'][0]->format( $args['dates_params']['format'] ); - $activities_count += count( $activities ); - $datasets[0]['data'][] = $activities_count; + $activities_count = $args['additive'] + ? $activities_count + $args['count_callback']( $activities ) + : $args['count_callback']( $activities ); + $datasets[0]['data'][] = $activities_count; + $datasets[0]['backgroundColor'][] = $args['colors']['background']( $activities_count ); + $datasets[0]['borderColor'][] = $args['colors']['border']( $activities_count ); } $data['datasets'] = $datasets; $this->render_chart( - md5( wp_json_encode( [ $query_params, $dates_params ] ) ), - $chart_params['type'], + md5( wp_json_encode( $args ) ), + $args['chart_params']['type'], $data, - $chart_params['options'] + $args['chart_params']['options'] ); } @@ -118,14 +148,14 @@ public function the_chart( $query_params = [], $dates_params = [], $chart_params public function render_chart( $id, $type, $data, $options = [] ) { $id = 'progress-planner-chart-' . $id; - $options['responsive'] = true; - // TODO: This should be properly enqueued. // phpcs:ignore echo ''; ?> - +
+ +
'; ?>
diff --git a/views/widgets/badges-progress.php b/views/widgets/badges-progress.php index 61157ddcd..0452f26f2 100644 --- a/views/widgets/badges-progress.php +++ b/views/widgets/badges-progress.php @@ -33,7 +33,9 @@
% - 🏆 + + 🏆 +
diff --git a/views/widgets/website-activity-score.php b/views/widgets/website-activity-score.php index 4aaf38123..16c2db43c 100644 --- a/views/widgets/website-activity-score.php +++ b/views/widgets/website-activity-score.php @@ -43,7 +43,7 @@ ] ) ); -$prpl_pending_updates = wp_get_update_data()['counts']['total']; +$prpl_pending_updates = wp_get_update_data()['counts']['total']; // Target is the number of pending updates + the ones that have already been done. $prpl_maintenance_score = max( 1, $prpl_maintenance_count ) / max( 1, $prpl_maintenance_count + $prpl_pending_updates ); From 291aa2bf9791cb87bc49761ce06d8086c534a9d7 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 4 Mar 2024 11:09:24 +0200 Subject: [PATCH 115/490] Implement badges grouping --- includes/class-badges.php | 210 ++++++++++++------------------ views/widgets/badges-progress.php | 51 +++++--- 2 files changed, 112 insertions(+), 149 deletions(-) diff --git a/includes/class-badges.php b/includes/class-badges.php index c6d31b963..41fbbb080 100644 --- a/includes/class-badges.php +++ b/includes/class-badges.php @@ -90,7 +90,17 @@ public function get_badge_progress( $badge_id ) { return 0; } - return $badge['progress_callback'](); + $progress = []; + + foreach ( $badge['steps'] as $step ) { + $progress[] = [ + 'name' => $step['name'], + 'icon' => $step['icon'], + 'progress' => $badge['progress_callback']( $step['target'] ), + ]; + } + + return $progress; } /** @@ -99,159 +109,103 @@ public function get_badge_progress( $badge_id ) { * @return void */ private function register_badges() { - // First Post. - $this->register_badge( - 'first_post', - [ - 'name' => __( 'First Post', 'progress-planner' ), - 'description' => __( 'You published your first post.', 'progress-planner' ), - 'progress_callback' => function () { - $activities = \progress_planner()->get_query()->query_activities( - [ - 'category' => 'content', - 'type' => 'publish', - ] - ); - return empty( $activities ) ? 0 : 100; - }, - ] - ); - - // 100 posts. - $this->register_badge( - '100_posts', - [ - 'name' => __( '100 Posts', 'progress-planner' ), - 'description' => __( 'You published 100 posts.', 'progress-planner' ), - 'progress_callback' => function () { - $activities = \progress_planner()->get_query()->query_activities( - [ - 'category' => 'content', - 'type' => 'publish', - ] - ); - return min( count( $activities ), 100 ); - }, - ] - ); - - // 1000 posts + // Badges for number of posts. $this->register_badge( - '1000_posts', + 'content_published_count', [ - 'name' => __( '1000 Posts', 'progress-planner' ), - 'description' => __( 'You published 1000 posts.', 'progress-planner' ), - 'progress_callback' => function () { + 'steps' => [ + [ + 'target' => 100, + 'name' => __( '100 Posts', 'progress-planner' ), + 'icon' => '🏆', + ], + [ + 'target' => 1000, + 'name' => __( '1000 Posts', 'progress-planner' ), + 'icon' => '🏆', + ], + [ + 'target' => 2000, + 'name' => __( '2000 Posts', 'progress-planner' ), + 'icon' => '🏆', + ], + [ + 'target' => 5000, + 'name' => __( '5000 Posts', 'progress-planner' ), + 'icon' => '🏆', + ], + ], + 'progress_callback' => function ( $target ) { $activities = \progress_planner()->get_query()->query_activities( [ 'category' => 'content', 'type' => 'publish', ] ); - return min( floor( count( $activities ) / 10 ), 100 ); - }, - ] - ); - - // 2000 posts - $this->register_badge( - '2000_posts', - [ - 'name' => __( '1000 Posts', 'progress-planner' ), - 'description' => __( 'You published 1000 posts.', 'progress-planner' ), - 'progress_callback' => function () { - $activities = \progress_planner()->get_query()->query_activities( - [ - 'category' => 'content', - 'type' => 'publish', - ] - ); - return min( floor( count( $activities ) / 20 ), 100 ); - }, - ] - ); - - // 5000 posts - $this->register_badge( - '5000_posts', - [ - 'name' => __( '5000 Posts', 'progress-planner' ), - 'description' => __( 'You published 5000 posts.', 'progress-planner' ), - 'progress_callback' => function () { - $activities = \progress_planner()->get_query()->query_activities( - [ - 'category' => 'content', - 'type' => 'publish', - ] - ); - return min( floor( count( $activities ) / 50 ), 100 ); + return min( floor( 100 * count( $activities ) / $target ), 100 ); }, ] ); // 100 maintenance tasks. $this->register_badge( - '100_maintenance_tasks', + 'maintenance_tasks', [ - 'name' => __( '100 Maintenance Tasks', 'progress-planner' ), - 'description' => __( 'You completed 100 maintenance tasks.', 'progress-planner' ), - 'progress_callback' => function () { + 'steps' => [ + [ + 'target' => 10, + 'name' => __( '10 maintenance tasks', 'progress-planner' ), + 'icon' => '🏆', + ], + [ + 'target' => 100, + 'name' => __( '100 maintenance tasks', 'progress-planner' ), + 'icon' => '🏆', + ], + [ + 'target' => 1000, + 'name' => __( '1000 maintenance tasks', 'progress-planner' ), + 'icon' => '🏆', + ], + ], + 'progress_callback' => function ( $target ) { $activities = \progress_planner()->get_query()->query_activities( [ 'category' => 'maintenance', ] ); - return min( count( $activities ), 100 ); + return min( floor( 100 * count( $activities ) / $target ), 100 ); }, ] ); // Write a post for 10 consecutive weeks. $this->register_badge( - '10_weeks_consecutive_posts', - [ - 'name' => __( '10 Weeks Consecutive Posts', 'progress-planner' ), - 'description' => __( 'You wrote a post for 10 consecutive weeks.', 'progress-planner' ), - 'progress_callback' => function () { - $goal = new Goal_Recurring( - new Goal_Posts( - [ - 'id' => 'weekly_post', - 'title' => \esc_html__( 'Write a weekly blog post', 'progress-planner' ), - 'description' => \esc_html__( 'Streak: The number of weeks this goal has been accomplished consistently.', 'progress-planner' ), - 'status' => 'active', - 'priority' => 'low', - 'evaluate' => function ( $goal_object ) { - return (bool) count( - \progress_planner()->get_query()->query_activities( - [ - 'category' => 'content', - 'type' => 'publish', - 'start_date' => $goal_object->get_details()['start_date'], - 'end_date' => $goal_object->get_details()['end_date'], - ] - ) - ); - }, - ] - ), - 'weekly', - \progress_planner()->get_query()->get_oldest_activity()->get_date(), // Beginning of the stats. - new \DateTime() // Today. - ); - - return ( min( 100, $goal->get_streak()['max_streak'] * 10 ) ); - }, - ] - ); - - // Write a post for 100 consecutive weeks. - $this->register_badge( - '100_weeks_consecutive_posts', + 'consecutive_weeks_posts', [ - 'name' => __( '100 Weeks Consecutive Posts', 'progress-planner' ), - 'description' => __( 'You wrote a post for 10 consecutive weeks.', 'progress-planner' ), - 'progress_callback' => function () { + 'steps' => [ + [ + 'target' => 10, + 'name' => __( '10 weeks posting streak', 'progress-planner' ), + 'icon' => '🏆', + ], + [ + 'target' => 52, + 'name' => __( '52 weeks posting streak', 'progress-planner' ), + 'icon' => '🏆', + ], + [ + 'target' => 104, + 'name' => __( '104 weeks posting streak', 'progress-planner' ), + 'icon' => '🏆', + ], + [ + 'target' => 208, + 'name' => __( '208 weeks posting streak', 'progress-planner' ), + 'icon' => '🏆', + ], + ], + 'progress_callback' => function ( $target ) { $goal = new Goal_Recurring( new Goal_Posts( [ @@ -279,7 +233,7 @@ private function register_badges() { new \DateTime() // Today. ); - return ( min( 100, $goal->get_streak()['max_streak'] ) ); + return min( floor( 100 * $goal->get_streak()['max_streak'] / $target ), 100 ); }, ] ); diff --git a/views/widgets/badges-progress.php b/views/widgets/badges-progress.php index 0452f26f2..c7cd92adc 100644 --- a/views/widgets/badges-progress.php +++ b/views/widgets/badges-progress.php @@ -8,34 +8,43 @@ namespace ProgressPlanner; $prpl_badges = \progress_planner()->get_badges()->get_badges(); + +$prpl_get_progress_color = function ( $progress ) { + $color = 'var(--prpl-color-accent-red)'; + if ( $progress > 50 ) { + $color = 'var(--prpl-color-accent-orange)'; + } + if ( $progress > 75 ) { + $color = 'var(--prpl-color-accent-green)'; + } + return $color; +}; + ?>

- get_badges()->get_badge_progress( $prpl_badge['id'] ); - $prpl_badge_progress_color = 'var(--prpl-color-accent-red)'; - if ( $prpl_badge_progress > 50 ) { - $prpl_badge_progress_color = 'var(--prpl-color-accent-orange)'; - } - if ( $prpl_badge_progress > 75 ) { - $prpl_badge_progress_color = 'var(--prpl-color-accent-green)'; - } - ?>
-

- -

-
- -
-
- % - - 🏆 + get_badges()->get_badge_progress( $prpl_badge['id'] ); ?> + $prpl_badge_step_progress ) : ?> + +

+ + +

+ +

+
+ +
+
+ % +
+ -
+ +
From e8e2f3a1001eb84233427873b6bd8c52d502dbb9 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 4 Mar 2024 11:11:54 +0200 Subject: [PATCH 116/490] CSS fix --- assets/css/admin.css | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/assets/css/admin.css b/assets/css/admin.css index 287d714c0..39fa09682 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -129,14 +129,10 @@ Set variables. margin-top: -1em; } -.progress-wrapper { - display: -} - .progress-wrapper .progress-bar { height: 1em; background-color: var(--prpl-color-gray-1); - width: calc(100% - 6em); + width: 100%; display: inline-block; } From d387b14577ff2c53a149f9d7e032bcbb8848b65e Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 4 Mar 2024 11:37:29 +0200 Subject: [PATCH 117/490] No need to query for tomorrow, date queries were fixed earlier today --- views/widgets/published-content-density.php | 2 +- views/widgets/published-words.php | 2 +- views/widgets/website-activity-score.php | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/views/widgets/published-content-density.php b/views/widgets/published-content-density.php index b2b607d1a..4fe2f94c0 100644 --- a/views/widgets/published-content-density.php +++ b/views/widgets/published-content-density.php @@ -41,7 +41,7 @@ function ( $activity ) { $prpl_query_args, [ 'start_date' => new \DateTime( '-7 days' ), - 'end_date' => new \DateTime( 'tomorrow' ), + 'end_date' => new \DateTime(), ] ) ) diff --git a/views/widgets/published-words.php b/views/widgets/published-words.php index 900a04ca6..1b333b865 100644 --- a/views/widgets/published-words.php +++ b/views/widgets/published-words.php @@ -35,7 +35,7 @@ function ( $activity ) { $prpl_query_args, [ 'start_date' => new \DateTime( '-7 days' ), - 'end_date' => new \DateTime( 'tomorrow' ), + 'end_date' => new \DateTime(), ] ) ) diff --git a/views/widgets/website-activity-score.php b/views/widgets/website-activity-score.php index 16c2db43c..d6df7d8cd 100644 --- a/views/widgets/website-activity-score.php +++ b/views/widgets/website-activity-score.php @@ -15,14 +15,14 @@ \progress_planner()->get_query()->query_activities( [ 'start_date' => new \DateTime( '-7 days' ), - 'end_date' => new \DateTime( 'tomorrow' ), + 'end_date' => new \DateTime(), 'category' => 'content', ] ), \progress_planner()->get_query()->query_activities( [ 'start_date' => new \DateTime( '-7 days' ), - 'end_date' => new \DateTime( 'tomorrow' ), + 'end_date' => new \DateTime(), 'category' => 'comments', ] ) @@ -38,7 +38,7 @@ \progress_planner()->get_query()->query_activities( [ 'start_date' => new \DateTime( '-7 days' ), - 'end_date' => new \DateTime( 'tomorrow' ), + 'end_date' => new \DateTime(), 'category' => 'maintenance', ] ) From 6a533bb05c0cffca6c135d36a26e6ff3b4b86f43 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 4 Mar 2024 12:50:21 +0200 Subject: [PATCH 118/490] CSS tweaks --- assets/css/admin.css | 88 +++++++++++++++++++++++++++++++++----------- 1 file changed, 66 insertions(+), 22 deletions(-) diff --git a/assets/css/admin.css b/assets/css/admin.css index 39fa09682..c3434d4ec 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -2,6 +2,13 @@ Set variables. */ .prpl-wrap { + --prpl-gap: 20px; + --prpl-column-min-width: 22rem; + --prpl-max-columns: 4; + --prpl-border-radius: 7px; + + --prpl-container-max-width: calc(var(--prpl-column-min-width) * var(--prpl-max-columns) + var(--prpl-gap) * (var(--prpl-max-columns) - 1)); + --prpl-color-gray-1: #e5e7eb; --prpl-color-gray-2: #d1d5db; --prpl-color-gray-3: #9ca3af; @@ -14,17 +21,58 @@ Set variables. --prpl-color-accent-purple: #0d6b9e; --prpl-color-accent-green: #14b8a6; + --prpl-color-headings: #38296d; + --prpl-color-text: var(--prpl-color-gray-6); + --prpl-color-link: #1e40af; + + --prpl-color-notification-green: #16a34a; + --prpl-color-notification-red: #e73136; + --prpl-background-orange: #fff9f0; + --prpl-background-purple: #f6f5fb; + --prpl-background-green: #f2faf9; + --prpl-background-red: #fff6f7; + --prpl-background-blue: #effbfe; + + --prpl-font-size-small: 0.875rem; /* 14px */ + --prpl-font-size-base: 1rem; /* 16px */ + --prpl-font-size-lg: 1.125rem; /* 18px */ + --prpl-font-size-xl: 1.25rem; /* 20px */ + --prpl-font-size-2xl: 1.5rem; /* 24px */ + --prpl-font-size-3xl: 2rem; /* 32px */ + --prpl-font-size-4xl: 3rem; /* 48px */ + --prpl-font-size-5xl: 4rem; /* 64px */ } .prpl-wrap { background: #fff; border: 1px solid var(--prpl-color-gray-3); - border-radius: 5px; - padding: 20px; + border-radius: var(--prpl-border-radius); + padding: var(--prpl-gap); + max-width: var(--prpl-container-max-width); + color: var(--prpl-color-text); + font-size: var(--prpl-font-size-base); + line-height: 1.4 +} + +.prpl-wrap p { + font-size: var(--prpl-font-size-base); +} + +.prpl-wrap h1, +.prpl-wrap h2, +.prpl-wrap h3, +.prpl-wrap h4, +.prpl-wrap h5, +.prpl-wrap h6 { + color: var(--prpl-color-headings); +} + +.prpl-wrap a { + color: var(--prpl-color-link); } -#progress-planner-scan-progress progress{ +#progress-planner-scan-progress progress { width: 100%; max-width: 500px; min-height: 1px; @@ -32,39 +80,35 @@ Set variables. .prpl-widgets-container { display: grid; - grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); - grid-gap: 20px; + grid-template-columns: repeat(auto-fit, minmax(var(--prpl-column-min-width), 1fr)); + grid-gap: var(--prpl-gap); } .prpl-widget-wrapper { - border: 1px solid var(--prpl-color-gray-3); - border-radius: 5px; - padding: 20px; + border: 1px solid var(--prpl-color-gray-2); + border-radius: var(--prpl-border-radius); + padding: var(--prpl-gap); display: flex; flex-direction: column; } .prpl-wrap .counter-big-wrapper { - background-color: var(--prpl-color-gray-1); - padding: 20px; - border-radius: 5px; + background-color: var(--prpl-background-purple); + padding: var(--prpl-gap); + border-radius: var(--prpl-border-radius); display: flex; flex-direction: column; align-items: center; } .prpl-wrap .counter-big-number { - font-size: 4rem; - line-height: 5rem; + font-size: var(--prpl-font-size-5xl); + line-height: 1; font-weight: 700; } .prpl-wrap .counter-big-text { - font-size: 1.5rem; -} - -.prpl-wrap .prpl-widget-content p { - font-size: 1.25em; + font-size: var(--prpl-font-size-2xl); } .prpl-graph-wrapper { @@ -80,7 +124,7 @@ Set variables. display: grid; grid-template-columns: 1fr 1fr; height: 100%; - grid-gap: 20px; + grid-gap: var(--prpl-gap); } .prpl-top-counter-bottom-content { @@ -98,9 +142,9 @@ Set variables. } .prpl-gauge-container { - padding: 20px; + padding: var(--prpl-gap); background-color: var(--prpl-background-orange); - border-radius: 5px; + border-radius: var(--prpl-border-radius); height: 50%; overflow: hidden; } @@ -124,7 +168,7 @@ Set variables. } .prpl-gauge-number { - font-size: 3em; + font-size: var(--prpl-font-size-4xl); line-height: 1; margin-top: -1em; } From 4ff95fc74be25b23f97451eb54e3b9684ac2bc56 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 4 Mar 2024 12:58:41 +0200 Subject: [PATCH 119/490] Make words graph green --- views/widgets/published-words.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/views/widgets/published-words.php b/views/widgets/published-words.php index 1b333b865..10265765b 100644 --- a/views/widgets/published-words.php +++ b/views/widgets/published-words.php @@ -41,6 +41,10 @@ function ( $activity ) { ) ); +$prpl_color_callback = function () { + return '#14b8a6'; +}; + ?>
@@ -88,6 +92,10 @@ function ( $activity ) { ], 'count_callback' => $prpl_count_words_callback, 'additive' => false, + 'colors' => [ + 'background' => $prpl_color_callback, + 'border' => $prpl_color_callback, + ], ], ); ?> From d658b48a5fbe960eb5fb8629cb72e2d8e1579db4 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 4 Mar 2024 13:08:05 +0200 Subject: [PATCH 120/490] Add some inline docs in views --- views/widgets/activity-scores.php | 7 +++++++ views/widgets/badges-progress.php | 8 ++++++++ views/widgets/published-content-density.php | 19 +++++++++++++++++++ views/widgets/published-content.php | 3 +++ views/widgets/published-pages.php | 3 +++ views/widgets/published-posts.php | 3 +++ views/widgets/published-words.php | 15 +++++++++++++++ views/widgets/website-activity-score.php | 8 +++++++- 8 files changed, 65 insertions(+), 1 deletion(-) diff --git a/views/widgets/activity-scores.php b/views/widgets/activity-scores.php index 8d148632e..bb6d598ec 100644 --- a/views/widgets/activity-scores.php +++ b/views/widgets/activity-scores.php @@ -7,6 +7,13 @@ namespace ProgressPlanner; +/** + * Callback to calculate the color of the chart. + * + * @param int $number The number to calculate the color for. + * + * @return string The color. + */ $prpl_color_callback = function ( $number ) { if ( $number > 90 ) { return '#14b8a6'; diff --git a/views/widgets/badges-progress.php b/views/widgets/badges-progress.php index c7cd92adc..9d5e05c48 100644 --- a/views/widgets/badges-progress.php +++ b/views/widgets/badges-progress.php @@ -7,8 +7,16 @@ namespace ProgressPlanner; +// Get an array of badges. $prpl_badges = \progress_planner()->get_badges()->get_badges(); +/** + * Callback to get the progress color. + * + * @param int $progress The progress. + * + * @return string The color. + */ $prpl_get_progress_color = function ( $progress ) { $color = 'var(--prpl-color-accent-red)'; if ( $progress > 50 ) { diff --git a/views/widgets/published-content-density.php b/views/widgets/published-content-density.php index 4fe2f94c0..0f95b68eb 100644 --- a/views/widgets/published-content-density.php +++ b/views/widgets/published-content-density.php @@ -9,11 +9,19 @@ use ProgressPlanner\Activities\Content_Helpers; +// Arguments for the query. $prpl_query_args = [ 'category' => 'content', 'type' => 'publish', ]; +/** + * Callback to count the words in the activities. + * + * @param \ProgressPlanner\Activity[] $activities The activities array. + * + * @return int + */ $prpl_count_words_callback = function ( $activities ) { return Content_Helpers::get_posts_stats_by_ids( array_map( @@ -25,16 +33,27 @@ function ( $activity ) { )['words']; }; +/** + * Callback to count the density of the activities. + * + * Returns the average number of words per activity. + * + * @param \ProgressPlanner\Activity[] $activities The activities array. + * + * @return int + */ $prpl_count_density_callback = function ( $activities ) use ( $prpl_count_words_callback ) { $words = $prpl_count_words_callback( $activities ); $count = count( $activities ); return round( $words / max( 1, $count ) ); }; +// Get the all-time average. $prpl_all_activities_density = $prpl_count_density_callback( \progress_planner()->get_query()->query_activities( $prpl_query_args ) ); +// Get the weekly average. $prpl_weekly_activities_density = $prpl_count_density_callback( \progress_planner()->get_query()->query_activities( array_merge( diff --git a/views/widgets/published-content.php b/views/widgets/published-content.php index 0997d716b..df8592a6f 100644 --- a/views/widgets/published-content.php +++ b/views/widgets/published-content.php @@ -9,6 +9,7 @@ use ProgressPlanner\Activities\Content_Helpers; +// Get the content published this week. $prpl_last_week_content = count( get_posts( [ @@ -23,6 +24,8 @@ ] ) ); + +// Get the total number of posts for this week. $prpl_all_content_count = 0; foreach ( Content_Helpers::get_post_types_names() as $prpl_post_type ) { $prpl_all_content_count += wp_count_posts( $prpl_post_type )->publish; diff --git a/views/widgets/published-pages.php b/views/widgets/published-pages.php index a0933fb0b..48a2e7155 100644 --- a/views/widgets/published-pages.php +++ b/views/widgets/published-pages.php @@ -7,6 +7,7 @@ namespace ProgressPlanner; +// Get the pages published in the last week. $prpl_last_week_pages = count( get_posts( [ @@ -21,6 +22,8 @@ ] ) ); + +// Get the total number of pages. $prpl_all_pages_count = wp_count_posts( 'page' ); ?> diff --git a/views/widgets/published-posts.php b/views/widgets/published-posts.php index 5aeeec1f8..240b062cf 100644 --- a/views/widgets/published-posts.php +++ b/views/widgets/published-posts.php @@ -7,6 +7,7 @@ namespace ProgressPlanner; +// Get the posts published in the last week. $prpl_last_week_posts = count( get_posts( [ @@ -21,6 +22,8 @@ ] ) ); + +// Get the total number of posts. $prpl_all_posts_count = wp_count_posts(); ?> diff --git a/views/widgets/published-words.php b/views/widgets/published-words.php index 10265765b..016d473f4 100644 --- a/views/widgets/published-words.php +++ b/views/widgets/published-words.php @@ -9,11 +9,19 @@ use ProgressPlanner\Activities\Content_Helpers; +// Arguments for the query. $prpl_query_args = [ 'category' => 'content', 'type' => 'publish', ]; +/** + * Callback to count the words in the activities. + * + * @param \ProgressPlanner\Activity[] $activities The activities array. + * + * @return int + */ $prpl_count_words_callback = function ( $activities ) { return Content_Helpers::get_posts_stats_by_ids( array_map( @@ -25,10 +33,12 @@ function ( $activity ) { )['words']; }; +// Get the all-time words count. $prpl_all_time_words = $prpl_count_words_callback( \progress_planner()->get_query()->query_activities( $prpl_query_args ) ); +// Get the weekly words count. $prpl_this_week_words = $prpl_count_words_callback( \progress_planner()->get_query()->query_activities( array_merge( @@ -41,6 +51,11 @@ function ( $activity ) { ) ); +/** + * Callback to get the color for the chart. + * + * @return string + */ $prpl_color_callback = function () { return '#14b8a6'; }; diff --git a/views/widgets/website-activity-score.php b/views/widgets/website-activity-score.php index d6df7d8cd..49cd19774 100644 --- a/views/widgets/website-activity-score.php +++ b/views/widgets/website-activity-score.php @@ -28,6 +28,7 @@ ) ) ); + // Target 5 content activities per week. $prpl_content_score = min( $prpl_content_count, 5 ) / 5; @@ -43,7 +44,9 @@ ] ) ); -$prpl_pending_updates = wp_get_update_data()['counts']['total']; + +// Get the number of pending updates. +$prpl_pending_updates = wp_get_update_data()['counts']['total']; // Target is the number of pending updates + the ones that have already been done. $prpl_maintenance_score = max( 1, $prpl_maintenance_count ) / max( 1, $prpl_maintenance_count + $prpl_pending_updates ); @@ -53,7 +56,10 @@ */ $prpl_score = 0.7 * $prpl_content_score + 0.3 * $prpl_maintenance_score; +// Get the score. $prpl_score = round( 100 * $prpl_score ); + +// Calculate the color. $prpl_gauge_color = 'var(--prpl-color-accent-red)'; if ( $prpl_score > 50 ) { $prpl_gauge_color = 'var(--prpl-color-accent-orange)'; From 9d5ad647c6fd95b0df588626d6f147da44aed48d Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 5 Mar 2024 11:23:55 +0200 Subject: [PATCH 121/490] Add on_install method --- includes/activities/class-content.php | 14 ++++++++++++++ includes/scan/class-maintenance.php | 17 +++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/includes/activities/class-content.php b/includes/activities/class-content.php index 0443519a2..aeca1ff16 100644 --- a/includes/activities/class-content.php +++ b/includes/activities/class-content.php @@ -8,12 +8,26 @@ namespace ProgressPlanner\Activities; use ProgressPlanner\Activity; +use ProgressPlanner\Date; +use ProgressPlanner\Activities\Content_Helpers; /** * Handler for posts activities. */ class Content extends Activity { + /** + * The points awarded for each activity. + * + * @var array + */ + const ACTIVITIES_POINTS = [ + 'publish' => 50, + 'update' => 10, + 'delete' => 5, + 'comment' => 2, + ]; + /** * Category of the activity. * diff --git a/includes/scan/class-maintenance.php b/includes/scan/class-maintenance.php index 4ddcb2e9f..d23147910 100644 --- a/includes/scan/class-maintenance.php +++ b/includes/scan/class-maintenance.php @@ -45,6 +45,23 @@ protected function register_hooks() { \add_action( 'switch_theme', [ $this, 'on_switch_theme' ], 10, 2 ); } + /** + * On install. + * + * @param \WP_Upgrader $upgrader The upgrader object. + * @param array $options The options. + * + * @return void + */ + public function on_install( $upgrader, $options ) { + if ( 'install' !== $options['action'] ) { + return; + } + $activity = new Activity_Maintenance(); + $activity->set_type( 'install_' . $this->get_install_type( $options ) ); + $activity->save(); + } + /** * On upgrade. * From 8b4b2c94d7afa974b55ba83560074f97fd4065df Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 5 Mar 2024 11:27:08 +0200 Subject: [PATCH 122/490] Add WIP page header --- assets/images/logo.png | Bin 0 -> 15437 bytes assets/js/admin.js | 7 ++++++ views/admin-page-header.php | 41 ++++++++++++++++++++++++++++++++++++ views/admin-page.php | 3 ++- 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 assets/images/logo.png create mode 100644 views/admin-page-header.php diff --git a/assets/images/logo.png b/assets/images/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..4e3278d7ca4aa77948d81ea5ecf8e1cb38cefb54 GIT binary patch literal 15437 zcmb8VWmH^CvjB=SSQs?82Dbr%ySuwHNPyt(KDdPhcSwS}6Wj?-aEB1w-Qi8n`R@Jh zdhgfUYxQ*R-Q`ugcUSd9sVd80pc0|Nz`$V0$x5ojz`#PF<5B<;^tZx}ml6gBwai9B zLRC&ef+>B@B#gRB|e^>X$|Qpwri)2uKPLmLZ>KpCu@15?=O{TO6Ar35Ww1 zVx(u--H=BW5}l`jg*Xp4qz|KJ7h?vGXY@%*Oz$mPLBU0UDd42T`*ciz(`uY&SL8O! z_hd!DH2`Ml!Y&_#mx4^8^obJn+PO$(u_}yqe8$hn~6^#u2Fbs@4;QY|S5>V7k3N8gKQuGLE zWbyV=YmkVHS%XM%$PR)*crb!dWB4?1q6O3eKD2aLKP6lw7R0-@(SZ0=N1szt#-;8M zdctMVe^V=MTlEE|(w#fPl=_Ab$p z-V861^H5IiHno;Q7-XGtzp{U4qx|_!dXz)v2uonZu(7Dq&Hkfl7c<>iyWTHB!tyh{ zov8Mn4|+*tj1|cg7pCJJ2JdxrK4Vi})1B-7dg7DYRIAJSnSh>U=`5f2Y8V?a!}b{> ze>;J5*E}(MopO^y`%-Bltnh=Inqfs}Nx;|PRS?#dwTM^$2M_DSv@I*GI1$^ZQ|cUc zA(FzDcZsliCoiYs4{rFDPp-D1->uR{Z_siqfiQkBq<3&Cz-V3KAh+CZgLL-UNSPlX zgFY3-;XKa7w*z165J>6}-I&mrh+zuX4oBU+WHJLHfX5G6j>keUBmpvcmg8@KA$Bbq z!u&}XyT4*dEOUbin$wP#Oyb+h3{W5tMQ{m1)eJ(KgbnY))rA$B?LDCmw z83g}Xln5BiTuo#LM+aIYip&O??Q{22wM|N$6l6CVGgDDXt$3 z4iI6Jf8ET}(t;NDKfCC(&n8Lh$ zYmIuGrMINPJ9#>J^94->3X`*YNNxfTtUt(wqF=%(&1XQg1TyGoIB{})7T^nzRGR!K z;i%=P|0u-{Jbuh~Fh=!_u8AEwH(@JkE1oZmL4tj^2N=29oR>ry(JI7s0C97n8QqY~ zf&7HvgzDst1Mn7$Ep)!mV6*+a#tSxpx&si18weYS{0b)`_K9u}iv&dsft50|I@<{{ zsn{$<@Jf;*D+sfBTx?K0|{ zEC;Rkr<70czS)0cR7cyV+$T*}oTF<^H2+EX$Nmq|10cjJ@(z50FK#p;DQDlVcz7)99ounJTe zyh;XihTpi?cfPpTuroW>%IRq6-BFv#p~7d< zVtn6mVTJc2I#oV;SUFibnXc4Y%X}6%%RC!enyMwUqp>S6wmUkJ8|d;v&80i0%c5zY zyaaB@{AhkabRc{ne(isdIwSMmn#h6ZCs8XGt2Mf<`g^1I_Zh8RY#%$mF-@gkY5K6Y zXA75pFWfGpnPQwjn8}#ro{XPdD>kZnmW(Lwos^qgte7t3EG;W(mGx|Js5qe(3L%qV zlXI*xj#z8%2o6Yk`S2|LObKrZpCT47Rv}hJxi~rN6b2646rwK2>ZR}B3!1VwUs#yq z{n<4_)#;NkDqlT7B@A7-) z%Qu&f_>K4__%h6728{X-dJgq=jefS4cKtPs4L_`u8gCkntyV3b2L}4Wtz0Jy2UE;i zhdk=+Gmmuyd<7DXvRA9yEB&*c10EfalCee?hMNz9oSi&%cb&#JzkJO$58sj-?95Wk zR?mv($6$G{J7nNxu^Cj?$hq9I(lQZtg1zf9^nF5WB>7l>^I=qJFz!%$|0cwyPw@kp zd51@n)7zF@XYyO8E8VTB-%%G==cBhrSL#>MXN>1Q2NlQJdq#&s2j+)$!$tjXw+>HR zr<*drkN>XzsQWeGCcyS-=~?at{6h0G0T&A|2|E_EAr%ng!E%5xgNBR1jTB6wJz1GY z*NxQ86cUKh9gYx@6fTI_fNn&(ge8q)K<4rONTS*I?&fR|D;(={WTR}$5KSUi;+9&D zT9}&u)XtP`fn#6sz?pf5nR88IO>&KSOgsLmo?vsIhuqp{WCe_rN<$y}^n=P_;>T16L>!Bt+fnSa?4O0Yju#?o2Ins%e^>f2jViW|JRB^unmZrIW=@fdRC_%h? zI`HC|ZpsPp?qeAHKY5ijGlWK?OY_i#eHn&|#Yi_GFLL*!nn{;QH+;BuRNrzWbCvK!F3_awxY)F9Ak6dX6D%dB)}30BRWTn} z`&4pQ^wS^)2W4+69I9%nO881W+Xf#tcQ8NVH!I+L<-n`|bbDz|_~#NS~nXkXsCvc@+645amO43L*nnuI!V{r8Q1 zWqo%oUq^JRyi8hVx{sQ@X73MLY~$z0jjaqF+rXY*Hw%x)I6D_#JPM~P>o!xKD+-t2 zG-bBpdl)ru`4nAO?yfT3>fSo6V79GaQ~VZFx&3_7LFOANM@#60ht%R>IL|EZV9^OyZ4?#8+*$op)Ii+-X7uD zY53%FmV7qbC%cx58h8?DfA?@@;t;q>5=TbrNA1IT?{O%Q?5TBXzt$9om>~50=>}{j z`1*Bt@IWP2g*5l8aA(@kL&&50)9jw@CC{s4`xl!pU&I?Dg@jP^fMGb;FkS|TFnmZb z!}c(dF;+YKHo+fWU<*;6=yK9qiu&IK@$Iq-n(4c8$ zwZ6~iFaQ42E2P|1bQ0$_qp3JJaA*|$b+zNwCiwl~`cWrLOD!S^Qh>-NboUx1a?oDG+{Mz;!PVN)jXQIZ0r~*NNmkDl z1_qzzZ-bRne|H9@KWC$<>!z!u$Zzgw&kDA1G_z#&vUmDR2S(6~A3C(RbOTd(+1oj| z@_PwU{R6=d9shmIMn&-th?}htm9CO1g@mJvB?UJth!sR7j7mX4A?RZ9fnQxx`akH< zJ0U7-H#aAKHa1UBPgYM(R!0{rHg-NfJ~j{s8wUpq6oSRo+rbU&#p2*f{V$RKp(APO zYVKm=FQfmx{*}|x%jUnF99;jS7F0pDzcXy?tRS}kr42;Kg(t`fdL)+gT+6Xki=AO_(dkQ&8F-jJYa6!mZN zU*fM=Npah*)|OcTXv`E+qEe-BROMY?nGJ`3#n4Cox-vrBK9?-*`7Z07J}cVc$N4k8 zo^A2;PlA%m&L~4?`k$tsJn3?tGK)dn;z2+P1VC`H3XN0 z{fCJxz)K#$lyVI5{4Kosd#nFT&spi+pwr`%u?H|=T_Lw#*=!5B_GvR|si z6nUa3U%QJhA!GPQ&`sGbtwz4r`hLh06_8BNV1g0DR|`dFkme{BN9 z19(XT)=7m>ScnqDLJx2mhCT%oWodM1`PS3@qX6J9fRMmM5b1J9a!=n$ocDRi7|8ia zogufh)@Z$ybm?D0xCnyOkjAlr-h2rWxh=En0p`o-=(kB)oq`7MsQ*ieR9__o{_%AX zo3?B&Aw-63EUeOZ_lA_-xEM{}y()reoQAr>rcsk^7#S3PO8 zj45`jJk9brrLDM@1;gG_XDj8V_>WaGq`El8n?0_Pl33QJxj(VB-Fc?97MrAzHkM1A zhuq|%UWM;7h$R5Bq4J9A{{=RM(I-5|vDwfmkBe9sbdljlzfk#0D(DaZq@CJ4fG3|F@eR@C4o41)@ho;HXN|6ZJU2wK!9ZEv6>_%}*{`I6f{wWK zH@;Y?MIk|UMpOvzRKH38r6L6lD_P@bM08?a9;cx18u)e#m)G@O{YtR^m@w$?ylL>1 zEw$a{Co*Wb0^!yufmq_aE_+tit9DtQdi;N)<`kU(vK$i7xeiGRDoEF-ydngX8)VdI zXiygr1V>`Q^=8RZM*EU|SN;nlK~Vq!inzg+>(?xM=A|LNH_?;a<%^PX!yj8m_=25E znDJdrG5k!G63WgiNK_Ifcsq422it@3%V8W*2XOqwN3Hb!SCI;4E2eJllgcn5!#|>S ziBbH9beW+tGB};p(-agT7@VnDLf^pZs30~#@V4kT7?6*jZ?R@W^%(8 ze>B6YZ$T(fM^FJIvw-|fxo{?a&dgLlAIJ6~C62vi+b<)IU^PJ~Ss)ESG6}d>LQ$VO zRXwdLxEBkxW}6h$zD`$X&epST{DPb)r3Ej+6b!F;GB6O#8^1`WGJb}|Qe23>6c-Ao)_S5pMKIV70- z(?zbhQcYW!!_%vi0!;1?@0upo8TA4rg;`hGB(_cRF{@`v-c%_664BP!;wO&Hx{kZ>7NXL>fU}d zk6;1M6M_=iWW@dO-EEu@{5}fsx46uBl;Avy4I;{BJ|4BNw3hj&8?;!1cdyF15ldPT zOY!DgHxNRRTFL2@j&C&peHrnCLTd=G?XOHKx1K`gO zfJPEqivqog+w|XeWSn{fm2#n7?Bdteqf%W!9G26?pQ^S=49mqjtFSl$Yz+4&Z2~!Q zQ{B6Ew!4aUdNOgCn4m4l#(P4|3S(U9c>9KEQuawPKGuTY`f?BL2#73uV#8taL?~91_ zDUE%(fdrXgImH4kSU;c>h;?i{y7`hf7LvSIa&`V?I&|wsrXkeH&@2UDRdPvt8tA?JsnD>6Tj4Qg6J*YBTxCbY31^W3SDcUiVu%M6+veB*1r z+%M50e9g>Jtb(RQ?**S^mD3qJ=DGB--vfBwV|6)T!(B%0Yxq2s&wx8V>l}xHLw9O= zKPfqieEa0eVSa&{b~)vvEZ0mA?#WcGxft0*d?Od|a{ks@la9>N{_Jc=wMdL1|D@nP z(^UO8$L0`gS@Xm_1>pz9$5T*eZF8rw4JeDxm3=hcc(TkSlKu@}&D!^g6i^>=-fKUVr#5PSG>Ya1x7Y@mH35DL~qIo;xl7TC;!K z1z4L~%{gydFgBVI=R_%YRjAtgJEAzjq%FSP5=Bl8p0D}u2DV0Uo#hA|Lo1!>tkShK zeP5$AB`=e~06L-R?hC`&c@_r9^4BhyR?^G#Vt%ed$DcQg-<^B3gK_epl;ip3p@I19 zfJx}uY{olButj5+UxL9kNuHh)cg4drJOpETKq5Y?*>`QPIjq`m@s09(mx85h`R-4= zTTR$0D4S#WI2#+?YY=)9(QfxU&E8y#PHWBi4I&A7VG{2nBMQ%J8cm%?LGd-Lay z`~xJYdrn@ppwXg{87l-Q*yBJSZK+LbOkOyCUa#E+vkxPEqT#SlMzu4i1%ZnRL%zXr zhF}H8kKQc?_|oi*BmcJlxu|?_DoVH{Oy4m#`Db5I1C8tGB~xjqSNDfB-hh(g1+^A> zRyHTADBfckL}XY0*6rm;;L63%3;YHerZ2RRZ#2sk;2AUR`HP!L2|n;x;Z(|@fF2gS zU&A_3+iFE4i$Fl}5fWu}y7?k{Ei`K{VLy&+7`wWTsi z4~-Ts-W$Q?)izcI>2hGc%k9**Ffl5$ELsF^DSltAh*d9Jlc9Q=frO5VtVTy%i9$s} z@L=kfI88xnIxc_^S?P+6;Z;EO`uE~<-PObAQje^0m4=ZUDsiU+PwWb|;~ILMLh5VC z@;4_8YY7~IsT=Ck9^vYkX z-Y8<&Mt@7W=Q<(u#vh4GxdG(2A=sNJ>=Sroh?|hvyskZPm8$w8F=$tCM>H25x+Rj! z&edHOxP8G@tXkS+W3(nh{~+I%;3)--4cyBV%Vv%PI~J=MLN*;PV+Qdqgi@lNV+{`_ zh~4e_Ak&3m_}KUM3jrCK?b~=Uf8h{}!%l2tf)6NJ!tQSlG|BM`ZZtb|b*tU-wnWS# zc%3)jeTGmRj4s^Zb|;Di8V^0Idhj~`X3o--PO^R;T8Q^8;?k_TMx9s6EZo{S+stjT z6wK#FvTsooq#`aAssrbh<_yIvGMBO(8}~mi)Mz-ptT?7Pz3nf2SZu!px%oZ{T_?2$ zDyHkdx~|SVjHI3fO`W5)Jm}}A2Uf5OXtOs-0BVI({XWA*nZIUvO&7Cf0FPKnymjEJiDrpN)hdpI$Y5kI(4_NoC1>8<2?)3W*1 zD*BOH`N`wF7yBGdg z1WJpa1y9wTI#0bFdcGgAR{TvfE)LkTwciO2EG6%+FX&($B~Slg$u}wFCrwC&P=rpE zZnshdq@6qI-$2@}?}6ZD8#GWT{?$1cCHQ`7e)b_nXrR$~Y>CG7t~jN32jf}|qFQzV zyxUGi3lEP)o&O#iX2>nP$X#pSFpBO*N1WErE2c-cIUUAu1Z?jg80d<2r=EH+X7Eu0 zObFc~jGCAUZszOxmM#o6G7UJ)ley@Zk+ zJ8>m*`_I*i{D+s=>a%GcVrFGF6!2rm&rf`=($rq+BcQtu<01rf;;7ezgR57@&PPqO z=hcX}k;yM(v|{EGL}T3T_KG)}Dbia9WO|bt)5uZ{ z=h3WHc+|K4w0(_xeGIv?$vWlEAv)z$>xGbN_e-(8>1Tg6e~p&Wt(FpYWIRybh@tL> zeDG8Hq7w%hr-}5oF|g;+)u(4fDu)}D`Wt#^6*HwD$R2O>!PGvId@X9$qr0!X!T)Fo z#d`7G72fAnuSnnt<T0dd)s~Ih#Ogd2H%3}FPKh>1-fQn@KFFmT{IvEpO!u)&=Rk}}#=yB;QZi4PQsGk{tJ3c< z@UH6Unn@nzl7Tp3DyzMA)lUmCHB;Bg-K?Dbq~bgzuEY*WcO`K zM?h%uL3v>aVc;%tsT#6j`DlKIXLLqI!fw8Bj1JS)rwF0=NV>Z%{R}^?U5k}I7PJwr zg8y~O-9{F0oJrTiv;IV%xohN4J?NQC@3> z^Bn_28XaSI2kPxlTb)eseajT}`p=Vfa>8utemHMMe*@_Qz?b3hlb!Psg{m>EtaZ_8 z0r?I7=RKCi>f>JZc$Xy==J@bfJwlMV@9*fpQjP^aS*2OswF61nbuCBrQ?BouIWIND#y^RTt`yFNBB|pvyIO(8gR9thWJ$?=ouMv+}S+E2I7~f{M40bpgjajRl_1VOFWkBJeJUheM-v4gs zG0x*pY!H7UP%qg){Xh z^mm&P)4%lYNjt5nAjI>pK^*-)c}vxPVId#~7i5XmUt!7Ld6EfL*)xmDP1(G5sJ-hh z)N~zQe9ud_k-EarI?csVeAU&Mz-BcUV4}K&nz1W5&)COseRNp7FUQ#J$tjSe;_%XQg^|qqQoI4>^7%*yku+rk% zvoy9DljMvNJhmG6aK+b7K68J;<@|~6RDyoBzWke`W?9RDK#Z1v@>~qJxak7lY|erQ z$kwy7FEpx`ky5u`sEh;a_mRp&SLpDcAiL$JTLN@a5YM&ll?wbNDNhq2Z&DV0SFG8FX$$?J9+#vBwJCk_;Vs- zP{j89$qdx6#o1a*)-yo*v>g-$JfavW8NrXXa;;ikJyOiIoo~{6wx&S{kI8&%8!BBT z{+h2ewt>k|rCZBm*x|w=xif%rI?(@QdRDCf7*%PwfZu$&Uth>)%FKQ$N7DRe9gxP} z>Z|LHUI6+#IR&C0^BRe}iRS~O0+N2Ib*ikiWXdg@J1%PEc7psNu73zFeTsUtwwdLV^ zwBv9#_NH*u(-8=ns35*dEOpWs?fNk39E_4@$()jT4P|7n3N7Ju@kU6y&ugV(>EM=+^8kg(1QRT#PCu$I6IjJ$pzHmv9Zu8>(hDT`7 z)#m!h;PhwD*+G6RLnr9O|6p1F_b1zhaNy9?k%DlN z0Pbbet%s^4u5f4aygei6-itowBz7idKMQz<4vS8?x4U%C49!OPprCI=<6DX)9SY7% zP z3lW?Hf}SOT1_o89TBdWMPg8GXxrOR0zB&9 za8z}0bsd#c8S~RkrH5{w?&}@5IWM6HmHZ=~9i=A{*H;ztj682Zq&$W~b8g#5ZWEik zSqy!N^~7uZp7w9*-p0pLiKc(LUR zAbC|h*|dm1rmmcGBU8$^>@VZ#@;$PN8a1<61Tpn0$f}dsd4z>+>96)yhYh86okwA4 z5XQ2X+qX1%-49}aeZ0-#>AK?cq~DeeBKX8^sszw(xw?99J(H(9n59UJoPua;K1go$eYT(L}}qvDcJCHzic1K`19pUn%$Q&A0U=D&h$E zT>~vT!nEtVbr4)!jEiTFqRT2Nz3HNEkwrjyQUu7!$yGmowZaLOj-Kj+3WY=HCXe2S z4Ie;@;G>1BKrKc-7YUhU@kPygp`1@fCX%eQrv47(1bsWT^RhplQKhDpIv414u9#=Xe@6 zSlEUeyeKDC#5&)bMR)2}AYSV{EGh|Ib$sq~We6N{eq~Ki20n}G7-<)+++rqgNuw6TiUoR>J1KlA~EP#c1=LKguWLRc8xzP z+|iWwZA2$Sf>6^Sk+8%_zZogBUN2a9Z@b+xoz9ig;a^ZcnZ1^&v~hjz6ZCSgnW>p} z2RWY8C-I@P$^+;b<>=oKK+C;ZE3rTBNA%7ODrh;8Pp3b!CB}it+W7Cg17s4qrBKAI zCO%bwI4KkXtNaAHIXND;`wVE@`aD1y$k`jN(a?F!tJ0dt?(emm$PTq~=#rtZU~yAX z5KlC^(|d=!9(dQhyDwZEvXuw6AJ~FtVwQgVqWNA5wUCMy3ty|eoLo5O8$oKVo{i`M zuN1gKB(p9VBtJR8lx~^K?NMHc>(=gLdg#rAY~b&-0YR^4GxN*%umQ$AuCN{UW_n6M z$=6|Ci>_2imlx^-?F9`bf%D`#)>W*}XsAvCT@Bu%SKr3x{b(UI7It7Ox~jP96)7#{ zRr|g3-NT^Vw%bc;dz}_li?VcB|y`oX)#89K3qFVVW^Y>O)L<@6k{xn?AZ= zkl_fO!x|q z1~J}e90(3%9sfdKq$<@aqu=!g*^A%p)|}=AR;A|%KKgUw*%71Atdrb8)V>>X+OmH$ z{%#It>q^0@oo}I8F$gi;l;#Y+I*l(m7R}Z29 zLe-}l&Axx83utXt3#?AUi3Q$&XAglZm@jc(1JNUJiJM34(<*Kac$Gn9S7ZzbuKQ18t$H7>(J#pChXIHA#NNE^|`kF zYEdEX@DRDUw|0(Y?s${MxHAxUir9N{r2k#{HjIPPqA5Ui5zMH%BbN8seTl3P@@e)0 zme+SKSHwYJyI*BI+YEe>MjZOHr9ZBQt@cueKt?&D^|G-Ly5qVO1v;xYt1KhSRbi>ppgu8v)Av`%7XozpwFgQYh4 z>;pI)x>M>8Bg(?KC}N1}QUKf2#a0@{OfGcl1KFLUV7k1$FFYjs&3KiI=X|pElfSgv z+uBIY*|(7&bAxgJbSx9BYmkwmyXNW!JF_IoacX~B4b~OI&jc=X{BGep(V@=awS++@ zSP_fV(u&$tuncWjjzcaJ9-ym>@IEHwLFs0Q(pI;e7aM!i{Hp71|Hq>1V&RFEod>CR z1F7}xGJ%nRB7uL=io>%hmc@*`PU-!o!Jn%oXquW6cn_C>jA(+S1I zJXkfSh(!U<9LGTGW)n5_)~U9O2aLK8Pwh*`K3tJ4>}i-saRcZ7e)x{awGFi`h(i^= z4cbHZL*-w7jng%4r8+vS8%hXt=wW@xtWo}0GvA38C#q7OIZ_a&)<2)|)#nUvLJ@phZ&>myZE z_0n|yaJTIpxZRcNi|n?HK>13(iK`autp(+Z)t13k*4t>#MqgIUFL!MF@Y8kj zALuc%xh%^Zzbh-9mIK|2gAAlg9Vof92Ps!Q^< zD{?*HMkhpUOSN*B&NrY3Njg8dK59l3T=uJK8WtddKUepLu1?c%^)Gl_2i={b=>{A- zncAoIe9j4Hr7YL&K+Mr^)<-2+b~=6bH{BZ=*F6Wctjr$gwGF*2Zv$wQ@EGFiD8Dv5 zoHFnu!y!HFwYK&avkQR=)DlrLFkL?xJL)FCAikXm@oXv!Bp76GuoWh|KC@leORfI6 zx@E{x;MP;Z7!KG9iH=*|5nJ{7eR`fvi$Ito@%Re+Rc52()0ailN%j@DJ?p2n-!_ly z2KDU$g1D&*bfv50glKd`3fnPn(BCAIm6heBpvDpL6k7}XT=7C!DM1#-aOIIlyMagi z)68`I33Eq5<|tdX)NFni%}>nkal}OggDbvh=$&Pmni!!Ym=5d#gw_J<1jOb8gy#t< zgA-BR3q-yqY|Z9LcM)m}kZQ}_FREpY&&Jy-Y`Tb5?X}4gUs5<6v^zUUcP0XiN(YH8 z9@?@~868;L>xIkxt&rYUsh7Hy0f^sD5RpSxO#KM3D4dbe(hv`etF!sr<5GV+)vSK1xQ;U!3g}mz7rO+mFkK-|v6> z3b(dm-FbzIl$z;W+Vi@~BhtfSM6MO(tqjmTA|Ug*aj<;Kk$qA_L+ZO}-5U<`9SqC? zH)P-Gky1^be6EkR))n6jXdiMbnf^Q-%$Q}I*y5wCrqFsC8iv5PhJO5Q){+MWqNgn)b&%y`}QIE!8&7YmjdXfOP4YR*q;?JW5i}fJHgvC?RFxSD8;p{Z1GAMEk-(tl6R?pm_eS~0 ztGBClaMp;|z!~E-210XxR1u`h4h+|L7u%e5H6*$xLeEsNW~ioZ@x<=!?)I8yH_$uI zjuQNHe_;8>3}VOvZTM zjALZ?6Fy2%o-vu%*1#<{xBp&2EKd?jw}Xu~5d!I3q*MToG-hv% zy!4;ULsQVgzN^4rABRDL;`&Ki<6Q|S2#hU%@H_D}(udg zh)5#A`jhkBQB^A*Bcd_UjqD-({24cEF zt$o7QIo?2vP~Og?+wpl5s`qYo#`Fq~1Nqhb+Ws5QAcb3r&Rl;tk!dk3254$6= z!H90l{+Y57^RwfoB72+qgGk8g9ryBi>FJDi`8$Lo`Q|iX4%c`5R+*>o9nVh-3Zwb6 z{olD4)QH)Nn>G)uHsIbI2^T=_I%*EpF#0NGz`3MnqU?1Lq1O1W=BX1Nlne7Ol=17Q z*skUvbbbeQx*AicHtu$pz+!FGhJ#2@3sje_zq;tk0hn3Qc@*DFt0<29{CP^l%&w!A z_$rNIy8XjuZfDpQ{Y?`AW45*6R1T1!v2oyIe1G(JJN9?Dfvq^GO{GOUME6eis9%6- z&_p*exXX!lI?h9g`y|i2Z==?%r`&$JI=@DJ-{8hJ0Lt=2rs_f2zTaHjltj_1m>ivK zZb~uY%I{$&75vO^&Qh0)DG$g(k+R{@t>8%;)hr)f1K+Z2)R%X((AgNZ&nO2$*68f0ak{36fbrWfnF zHkxQ40drAiWZvktN^1_=CDdpK-kd1~8!ofECOvB!TF|uLIH_q8)%W?>Pln-GxrWji zc*0UbC=XEoNJT6edQ>~Y3gJ2|l0h~2I2@;?GqM?*tAtABl(ZX%LI_oIhoHIplG$}cUf6?{7fnKDmc`=8~ffNd8 z9l{()neALuCcuH~jfff{iI{ek2PhMAx(^c{T6NK+&dTUT?n1f%P8_N=JY3NW^eEsh z41R5NR;)tv+(0z=$5GTIr9=2d77r}zehVQ+f4#yRa<_x?ELUSq_~Hq zCIj8eE={i|og6JsA?3jnMaS5ikJ%(DaD9{=Qqi}TR1i^>3k|ZLAaJA3Ow{Uw=uOCK zG@ALy!MYvwC`$0=)!{W34Z(2`}D9Ag97Tk{EiJdNmN6aI^-@K3*)AysfSg7TBmU|A10D%TZTb6&|J#FsL-( z7S+P88zi<)LSV?KNY^Ug@M~!ndDs9gf%EkmYcvWfpuUpg@X*T_*%6 ziPOIXVB$KEZTWVI@fZ6a(iUsCSN_`m)KRxdo||1vB~us5=r)PSE{cxOC2EZ=-Zu8e zYrQ3%rh4Dzuu-WQg)s`&EQkOA308dvX^Vr;JGy!sj6hQVg{Y!POn=K*zKO0=03Lee zSMllVV(@2H?7w`;2>?>!k@JhNr)+d}khjL!0HsW>ol;F~_&ykRAOXCZ3V@Hv06qy9 z8Qge|t$amk))JG9(GIRwQ@nyT`uq2R@h%BI&PXaZKamZeacMqo$vu4>JW_ZtuCTU2I*kbitKAex5~`~g`DnRE=h^g>MMFE1k`dP>Q}KzV@L zyIeyY_&!kt_+VPdiu-Dw;4Ad6%aY}?Hdz>i6>n+H_Ha4>%AOP~iUYS5WK8`09^2Xj z_)8$f6bl|@RCEI+*g1PoF8H$;+`2O^KReJ2so*m(;P+RO;qjcSu#7gIAHKB)trI>f z4`$o%inX`IopEOW^$HwPK^pKWW^Ee%n?8rd+J`5n*f&tqQ6OQ*1~)4L$}v}I5q+}1 zn0ms5DL{>$jNWH2PA|xd9Gy^Jf{yE|Uia)L+kQnGOaJq)3)z95e*sK|k~{O+l3woc zN~hHWX9+(xX2pD_q5OyL@5JC{Wk7i^C}w}k%=MhNo`LqStA<5a=pgdqvD=N8O)GD{ zuLr8DCA*w+eVPL6S#oCoL;KSn`a5ND*{htwyMKaH6(ouxCI;k!S`LQ&6Fs!5B%72| g$ov0$?up!kC659otV#n~kcN?yQkJX~Hx2oJ0QUgG*#H0l literal 0 HcmV?d00001 diff --git a/assets/js/admin.js b/assets/js/admin.js index 9c8fe7a42..5a3660741 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -137,3 +137,10 @@ progressPlannerDomReady( () => { } ); } } ); + +document.getElementById( 'prpl-select-range' ).addEventListener( 'change', function() { + const range = this.value; + const url = new URL( window.location.href ); + url.searchParams.set( 'range', range ); + window.location.href = url.href; +} ); diff --git a/views/admin-page-header.php b/views/admin-page-header.php new file mode 100644 index 000000000..023c38834 --- /dev/null +++ b/views/admin-page-header.php @@ -0,0 +1,41 @@ + + diff --git a/views/admin-page.php b/views/admin-page.php index 234f83679..19a47d13e 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -17,7 +17,8 @@ ); ?>
-

+

+ From 31839d7a14edaffbf71ba0c0e24b70b1303e525d Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 5 Mar 2024 11:28:38 +0200 Subject: [PATCH 123/490] Add get_points methods in activities --- includes/activities/class-content.php | 47 +++++++++++++++++++++++ includes/activities/class-maintenance.php | 22 +++++++++++ includes/class-activity.php | 16 ++++++++ includes/class-date.php | 10 +++++ 4 files changed, 95 insertions(+) diff --git a/includes/activities/class-content.php b/includes/activities/class-content.php index aeca1ff16..69d3f1b75 100644 --- a/includes/activities/class-content.php +++ b/includes/activities/class-content.php @@ -43,4 +43,51 @@ class Content extends Activity { public function get_post() { return \get_post( $this->data_id ); } + + /** + * Get the points for an activity. + * + * @param \DateTime $date The date for which we want to get the points of the activity. + * + * @return int + */ + public function get_points( $date ) { + $points = self::ACTIVITIES_POINTS[ $this->get_type() ]; + $post = $this->get_post(); + if ( ! $post ) { + return 0; + } + $words = Content_Helpers::get_word_count( $post->post_content ); + if ( $words > 1000 ) { + $points -= 10; + } elseif ( $words > 350 ) { + $points += 5; + } elseif ( $words > 100 ) { + $points += 2; + } else { + $points -= 2; + } + + // Decay the points based on the age of the activity. + $days = Date::get_days_between_dates( $date, $this->get_date() ); + + // If $days is > 0, then the activity is in the future. + if ( $days > 0 ) { + return 0; + } + $days = absint( $days ); + + // Maximum range for awarded points is 30 days. + if ( $days >= 30 ) { + return 0; + } + + // If the activity is new (less than 7 days old), award full points. + if ( $days < 7 ) { + return (int) $points; + } + + // Decay the points based on the age of the activity. + return (int) $points * ( 1 - $days / 30 ); + } } diff --git a/includes/activities/class-maintenance.php b/includes/activities/class-maintenance.php index 6210322e0..4889f5ecb 100644 --- a/includes/activities/class-maintenance.php +++ b/includes/activities/class-maintenance.php @@ -8,6 +8,7 @@ namespace ProgressPlanner\Activities; use ProgressPlanner\Activity; +use ProgressPlanner\Date; /** * Handle activities for Core updates. @@ -41,4 +42,25 @@ public function save() { parent::save(); } + + /** + * Get the points for an activity. + * + * @param \DateTime $date The date for which we want to get the points of the activity. + * + * @return int + */ + public function get_points( $date ) { + $points = 7; + if ( str_starts_with( $this->type, 'install_' ) ) { + $points = 5; + } elseif ( str_starts_with( $this->type, 'delete_' ) ) { + $points = 3; + } + + // Decay the points based on the age of the activity. + $days = Date::get_days_between_dates( $date, $this->get_date() ); + + return ( $days > 0 && $days < 7 ) ? $points : 0; + } } diff --git a/includes/class-activity.php b/includes/class-activity.php index f3be1a1a4..f436d0d77 100644 --- a/includes/class-activity.php +++ b/includes/class-activity.php @@ -7,6 +7,8 @@ namespace ProgressPlanner; +use ProgressPlanner\Date; + /** * Activity class. */ @@ -195,4 +197,18 @@ public function save() { public function delete() { \progress_planner()->get_query()->delete_activity( $this ); } + + /** + * Get the points for an activity. + * + * @param \DateTime $date The date for which we want to get the points of the activity. + * + * @return int + */ + public function get_points( $date ) { + $days = Date::get_days_between_dates( $date, $this->get_date() ); + return ( $days > 0 && $days < 7 ) + ? 10 + : 10 * ( 1 - $days / 30 ); + } } diff --git a/includes/class-date.php b/includes/class-date.php index dc45204ce..bddc3cc2f 100644 --- a/includes/class-date.php +++ b/includes/class-date.php @@ -111,4 +111,14 @@ public static function get_start_of_week( $date ) { public static function get_start_of_month( $date ) { return $date->modify( 'first day of this month' ); } + + /** + * Get number of days between two dates. + * + * @param \DateTime $date1 The first date. + * @param \DateTime $date2 The second date. + */ + public static function get_days_between_dates( $date1, $date2 ) { + return (int) $date1->diff( $date2 )->format( '%R%a' ); + } } From 4fb98db33ba00dec7dff1c57f5972a9bf3081153 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 5 Mar 2024 12:04:28 +0200 Subject: [PATCH 124/490] WIP - rolling charts --- includes/activities/class-content.php | 11 +++-- includes/activities/class-maintenance.php | 8 ++- includes/class-chart.php | 46 +++++++++++------- views/widgets/activity-scores.php | 20 +++++--- views/widgets/published-pages.php | 1 + views/widgets/published-posts.php | 1 + views/widgets/published-words.php | 2 +- views/widgets/website-activity-score.php | 59 ++++++----------------- 8 files changed, 68 insertions(+), 80 deletions(-) diff --git a/includes/activities/class-content.php b/includes/activities/class-content.php index 69d3f1b75..a7b869489 100644 --- a/includes/activities/class-content.php +++ b/includes/activities/class-content.php @@ -22,9 +22,9 @@ class Content extends Activity { * @var array */ const ACTIVITIES_POINTS = [ - 'publish' => 50, - 'update' => 10, - 'delete' => 5, + 'publish' => 20, + 'update' => 7, + 'delete' => 3, 'comment' => 2, ]; @@ -75,6 +75,7 @@ public function get_points( $date ) { if ( $days > 0 ) { return 0; } + $days = absint( $days ); // Maximum range for awarded points is 30 days. @@ -84,10 +85,10 @@ public function get_points( $date ) { // If the activity is new (less than 7 days old), award full points. if ( $days < 7 ) { - return (int) $points; + return round( $points ); } // Decay the points based on the age of the activity. - return (int) $points * ( 1 - $days / 30 ); + return round( $points * ( 1 - $days / 30 ) ); } } diff --git a/includes/activities/class-maintenance.php b/includes/activities/class-maintenance.php index 4889f5ecb..901c29971 100644 --- a/includes/activities/class-maintenance.php +++ b/includes/activities/class-maintenance.php @@ -51,11 +51,9 @@ public function save() { * @return int */ public function get_points( $date ) { - $points = 7; - if ( str_starts_with( $this->type, 'install_' ) ) { - $points = 5; - } elseif ( str_starts_with( $this->type, 'delete_' ) ) { - $points = 3; + $points = 2; + if ( str_starts_with( $this->type, 'install_' ) || str_starts_with( $this->type, 'delete_' ) ) { + $points = 1; } // Decay the points based on the age of the activity. diff --git a/includes/class-chart.php b/includes/class-chart.php index 768bfe6df..f1ad61570 100644 --- a/includes/class-chart.php +++ b/includes/class-chart.php @@ -42,7 +42,8 @@ public function the_chart( $args = [] ) { 'filter_results' => null, 'dates_params' => [], 'chart_params' => [], - 'additive' => true, + 'additive' => false, + 'rolling' => false, 'colors' => [ 'background' => function () { return '#534786'; @@ -94,7 +95,7 @@ public function the_chart( $args = [] ) { ]; // Calculate zero stats to be used as the baseline. - $activities_count = 0; + $score = 0; if ( $args['additive'] ) { $activities = \progress_planner()->get_query()->query_activities( array_merge( @@ -108,31 +109,40 @@ public function the_chart( $args = [] ) { if ( $args['filter_results'] ) { $activities = $args['filter_results']( $activities ); } - $activities_count = $args['count_callback']( $activities ); + $score = $args['count_callback']( $activities ); } foreach ( $periods as $period ) { - $activities = \progress_planner()->get_query()->query_activities( - array_merge( - $args['query_params'], - [ - 'start_date' => $period['start'], - 'end_date' => $period['end'], - ] - ) - ); + $activities = $args['rolling'] + ? \progress_planner()->get_query()->query_activities( + array_merge( + $args['query_params'], + [ + 'start_date' => $period['start']->modify( '-61 days' ), + 'end_date' => $period['end'], + ] + ) + ) : \progress_planner()->get_query()->query_activities( + array_merge( + $args['query_params'], + [ + 'start_date' => $period['start'], + 'end_date' => $period['end'], + ] + ) + ); if ( $args['filter_results'] ) { $activities = $args['filter_results']( $activities ); } $data['labels'][] = $period['dates'][0]->format( $args['dates_params']['format'] ); - $activities_count = $args['additive'] - ? $activities_count + $args['count_callback']( $activities ) - : $args['count_callback']( $activities ); - $datasets[0]['data'][] = $activities_count; - $datasets[0]['backgroundColor'][] = $args['colors']['background']( $activities_count ); - $datasets[0]['borderColor'][] = $args['colors']['border']( $activities_count ); + $score = $args['additive'] + ? $score + $args['count_callback']( $activities, $period['start'] ) + : $args['count_callback']( $activities, $period['start'] ); + $datasets[0]['data'][] = $score; + $datasets[0]['backgroundColor'][] = $args['colors']['background']( $score ); + $datasets[0]['borderColor'][] = $args['colors']['border']( $score ); } $data['datasets'] = $datasets; diff --git a/views/widgets/activity-scores.php b/views/widgets/activity-scores.php index bb6d598ec..c034d582e 100644 --- a/views/widgets/activity-scores.php +++ b/views/widgets/activity-scores.php @@ -32,18 +32,26 @@ the_chart( [ - 'query_params' => [], - 'dates_params' => [ - 'start' => \DateTime::createFromFormat( 'Y-m-d', \gmdate( 'Y-m-01' ) )->modify( '-11 months' ), + 'query_params' => [], + 'dates_params' => [ + 'start' => \DateTime::createFromFormat( 'Y-m-d', \gmdate( 'Y-m-01' ) )->modify( '-24 months' ), 'end' => new \DateTime(), 'frequency' => 'monthly', 'format' => 'M', ], - 'chart_params' => [ + 'chart_params' => [ 'type' => 'bar', ], - 'additive' => false, - 'colors' => [ + 'count_callback' => function ( $activities, $date ) { + $score = 0; + foreach ( $activities as $activity ) { + $score += $activity->get_points( $date ); + } + return round( min( 100, $score ) ); + }, + 'additive' => false, + 'rolling' => true, + 'colors' => [ 'background' => $prpl_color_callback, 'border' => $prpl_color_callback, ], diff --git a/views/widgets/published-pages.php b/views/widgets/published-pages.php index 48a2e7155..ecd1b62d8 100644 --- a/views/widgets/published-pages.php +++ b/views/widgets/published-pages.php @@ -78,6 +78,7 @@ 'chart_params' => [ 'type' => 'line', ], + 'additive' => true, ] ); ?> diff --git a/views/widgets/published-posts.php b/views/widgets/published-posts.php index 240b062cf..aaf0f4098 100644 --- a/views/widgets/published-posts.php +++ b/views/widgets/published-posts.php @@ -78,6 +78,7 @@ 'chart_params' => [ 'type' => 'line', ], + 'additive' => true, ], ); ?> diff --git a/views/widgets/published-words.php b/views/widgets/published-words.php index 016d473f4..1aea7e967 100644 --- a/views/widgets/published-words.php +++ b/views/widgets/published-words.php @@ -107,7 +107,7 @@ function ( $activity ) { ], 'count_callback' => $prpl_count_words_callback, 'additive' => false, - 'colors' => [ + 'colors' => [ 'background' => $prpl_color_callback, 'border' => $prpl_color_callback, ], diff --git a/views/widgets/website-activity-score.php b/views/widgets/website-activity-score.php index 49cd19774..3175d8134 100644 --- a/views/widgets/website-activity-score.php +++ b/views/widgets/website-activity-score.php @@ -7,57 +7,26 @@ namespace ProgressPlanner; -/* - * Get the content score. - */ -$prpl_content_count = count( - array_merge( - \progress_planner()->get_query()->query_activities( - [ - 'start_date' => new \DateTime( '-7 days' ), - 'end_date' => new \DateTime(), - 'category' => 'content', - ] - ), - \progress_planner()->get_query()->query_activities( - [ - 'start_date' => new \DateTime( '-7 days' ), - 'end_date' => new \DateTime(), - 'category' => 'comments', - ] - ) - ) +$prpl_activities = \progress_planner()->get_query()->query_activities( + [ + 'start_date' => new \DateTime( '-31 days' ), + 'end_date' => new \DateTime(), + ] ); -// Target 5 content activities per week. -$prpl_content_score = min( $prpl_content_count, 5 ) / 5; - -/* - * Get the maintenance score. - */ -$prpl_maintenance_count = count( - \progress_planner()->get_query()->query_activities( - [ - 'start_date' => new \DateTime( '-7 days' ), - 'end_date' => new \DateTime(), - 'category' => 'maintenance', - ] - ) -); +$prpl_score = 0; +$prpl_current_date = new \DateTime(); +foreach ( $prpl_activities as $prpl_activity ) { + $prpl_score += $prpl_activity->get_points( $prpl_current_date ) / 2; +} +$prpl_score = min( 100, max( 0, $prpl_score / 2 ) ); // Get the number of pending updates. $prpl_pending_updates = wp_get_update_data()['counts']['total']; -// Target is the number of pending updates + the ones that have already been done. -$prpl_maintenance_score = max( 1, $prpl_maintenance_count ) / max( 1, $prpl_maintenance_count + $prpl_pending_updates ); - -/** - * Calculate the score. - */ -$prpl_score = 0.7 * $prpl_content_score + 0.3 * $prpl_maintenance_score; - -// Get the score. -$prpl_score = round( 100 * $prpl_score ); +// Reduce points for pending updates. +$prpl_pending_updates_penalty = min( min( $prpl_score / 2, 25 ), $prpl_pending_updates * 5 ); +$prpl_score -= $prpl_pending_updates_penalty; // Calculate the color. $prpl_gauge_color = 'var(--prpl-color-accent-red)'; From d47a0b81386588f836fd0bf52935ff9775a9892f Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 5 Mar 2024 12:31:43 +0200 Subject: [PATCH 125/490] wip - tweaks for scores --- includes/activities/class-content.php | 21 ++++++++++----------- includes/activities/class-maintenance.php | 4 ++++ includes/class-activity.php | 8 ++++++-- includes/class-chart.php | 8 ++++---- views/widgets/activity-scores.php | 5 +++-- views/widgets/website-activity-score.php | 4 ++-- 6 files changed, 29 insertions(+), 21 deletions(-) diff --git a/includes/activities/class-content.php b/includes/activities/class-content.php index a7b869489..ffb673ef9 100644 --- a/includes/activities/class-content.php +++ b/includes/activities/class-content.php @@ -22,10 +22,10 @@ class Content extends Activity { * @var array */ const ACTIVITIES_POINTS = [ - 'publish' => 20, - 'update' => 7, - 'delete' => 3, - 'comment' => 2, + 'publish' => 50, + 'update' => 20, + 'delete' => 10, + 'comment' => 5, ]; /** @@ -68,7 +68,6 @@ public function get_points( $date ) { $points -= 2; } - // Decay the points based on the age of the activity. $days = Date::get_days_between_dates( $date, $this->get_date() ); // If $days is > 0, then the activity is in the future. @@ -83,12 +82,12 @@ public function get_points( $date ) { return 0; } - // If the activity is new (less than 7 days old), award full points. - if ( $days < 7 ) { - return round( $points ); - } + $points = ( $days < 7 ) + ? round( $points ) // If the activity is new (less than 7 days old), award full points. + : round( $points * ( 1 - $days / 30 ) ); // Decay the points based on the age of the activity. + + error_log( 'Days: ' . $days . ' Points: ' . $points ); - // Decay the points based on the age of the activity. - return round( $points * ( 1 - $days / 30 ) ); + return $points; } } diff --git a/includes/activities/class-maintenance.php b/includes/activities/class-maintenance.php index 901c29971..6ab891ec4 100644 --- a/includes/activities/class-maintenance.php +++ b/includes/activities/class-maintenance.php @@ -58,6 +58,10 @@ public function get_points( $date ) { // Decay the points based on the age of the activity. $days = Date::get_days_between_dates( $date, $this->get_date() ); + if ( $days > 0 ) { + return 0; + } + $days = abs( $days ); return ( $days > 0 && $days < 7 ) ? $points : 0; } diff --git a/includes/class-activity.php b/includes/class-activity.php index f436d0d77..ca110cdda 100644 --- a/includes/class-activity.php +++ b/includes/class-activity.php @@ -207,8 +207,12 @@ public function delete() { */ public function get_points( $date ) { $days = Date::get_days_between_dates( $date, $this->get_date() ); - return ( $days > 0 && $days < 7 ) + if ( $days > 0 ) { + return 0; + } + $days = abs( $days ); + return ( $days < 0 && $days < 7 ) ? 10 - : 10 * ( 1 - $days / 30 ); + : round( 10 * ( 1 - $days / 30 ) ); } } diff --git a/includes/class-chart.php b/includes/class-chart.php index f1ad61570..bb157cf17 100644 --- a/includes/class-chart.php +++ b/includes/class-chart.php @@ -118,7 +118,7 @@ public function the_chart( $args = [] ) { array_merge( $args['query_params'], [ - 'start_date' => $period['start']->modify( '-61 days' ), + 'start_date' => $period['start']->modify( '-31 days' ), 'end_date' => $period['end'], ] ) @@ -137,9 +137,9 @@ public function the_chart( $args = [] ) { $data['labels'][] = $period['dates'][0]->format( $args['dates_params']['format'] ); - $score = $args['additive'] - ? $score + $args['count_callback']( $activities, $period['start'] ) - : $args['count_callback']( $activities, $period['start'] ); + $period_score = $args['count_callback']( $activities, $period['start'] ); + $score = $args['additive'] ? $score + $period_score : $period_score; + $datasets[0]['data'][] = $score; $datasets[0]['backgroundColor'][] = $args['colors']['background']( $score ); $datasets[0]['borderColor'][] = $args['colors']['border']( $score ); diff --git a/views/widgets/activity-scores.php b/views/widgets/activity-scores.php index c034d582e..57578075b 100644 --- a/views/widgets/activity-scores.php +++ b/views/widgets/activity-scores.php @@ -34,7 +34,7 @@ [ 'query_params' => [], 'dates_params' => [ - 'start' => \DateTime::createFromFormat( 'Y-m-d', \gmdate( 'Y-m-01' ) )->modify( '-24 months' ), + 'start' => \DateTime::createFromFormat( 'Y-m-d', \gmdate( 'Y-m-01' ) )->modify( '-12 months' ), 'end' => new \DateTime(), 'frequency' => 'monthly', 'format' => 'M', @@ -47,7 +47,8 @@ foreach ( $activities as $activity ) { $score += $activity->get_points( $date ); } - return round( min( 100, $score ) ); + $target = 200; // 200 points is 4 posts per week. + return round( ( $score / $target ) * 100 ); }, 'additive' => false, 'rolling' => true, diff --git a/views/widgets/website-activity-score.php b/views/widgets/website-activity-score.php index 3175d8134..4dcf52167 100644 --- a/views/widgets/website-activity-score.php +++ b/views/widgets/website-activity-score.php @@ -14,7 +14,7 @@ ] ); -$prpl_score = 0; +$prpl_score = 0; $prpl_current_date = new \DateTime(); foreach ( $prpl_activities as $prpl_activity ) { $prpl_score += $prpl_activity->get_points( $prpl_current_date ) / 2; @@ -26,7 +26,7 @@ // Reduce points for pending updates. $prpl_pending_updates_penalty = min( min( $prpl_score / 2, 25 ), $prpl_pending_updates * 5 ); -$prpl_score -= $prpl_pending_updates_penalty; +$prpl_score -= $prpl_pending_updates_penalty; // Calculate the color. $prpl_gauge_color = 'var(--prpl-color-accent-red)'; From 6dfcfcd5381f9cffc5a4f0e443e0bce2f83df54a Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 5 Mar 2024 12:36:53 +0200 Subject: [PATCH 126/490] implement 6/12-month switch --- views/admin-page-header.php | 8 ++++---- views/widgets/activity-scores.php | 5 ++++- views/widgets/published-content-density.php | 5 ++++- views/widgets/published-content.php | 5 ++++- views/widgets/published-pages.php | 5 ++++- views/widgets/published-posts.php | 5 ++++- views/widgets/published-words.php | 5 ++++- 7 files changed, 28 insertions(+), 10 deletions(-) diff --git a/views/admin-page-header.php b/views/admin-page-header.php index 023c38834..44cb897ed 100644 --- a/views/admin-page-header.php +++ b/views/admin-page-header.php @@ -5,8 +5,8 @@ * @package ProgressPlanner */ - // phpcs:ignore WordPress.Security.NonceVerification.Recommended -$prpl_active_range = isset( $_GET['range'] ) ? sanitize_text_field( wp_unslash( $_GET['range'] ) ) : '6-months'; +// phpcs:ignore WordPress.Security.NonceVerification.Recommended +$prpl_active_range = isset( $_GET['range'] ) ? sanitize_text_field( wp_unslash( $_GET['range'] ) ) : '-6 months'; ?>
diff --git a/views/widgets/activity-scores.php b/views/widgets/activity-scores.php index 75494b750..c6d339e64 100644 --- a/views/widgets/activity-scores.php +++ b/views/widgets/activity-scores.php @@ -9,6 +9,8 @@ // phpcs:ignore WordPress.Security.NonceVerification.Recommended $prpl_active_range = isset( $_GET['range'] ) ? sanitize_text_field( wp_unslash( $_GET['range'] ) ) : '-6 months'; +// phpcs:ignore WordPress.Security.NonceVerification.Recommended +$prpl_active_frequency = isset( $_GET['frequency'] ) ? sanitize_text_field( wp_unslash( $_GET['frequency'] ) ) : 'monthly'; /** * Callback to calculate the color of the chart. @@ -39,7 +41,7 @@ 'dates_params' => [ 'start' => \DateTime::createFromFormat( 'Y-m-d', \gmdate( 'Y-m-01' ) )->modify( $prpl_active_range ), 'end' => new \DateTime(), - 'frequency' => 'monthly', + 'frequency' => $prpl_active_frequency, 'format' => 'M', ], 'chart_params' => [ diff --git a/views/widgets/published-content-density.php b/views/widgets/published-content-density.php index 11039e951..c0c90f1c0 100644 --- a/views/widgets/published-content-density.php +++ b/views/widgets/published-content-density.php @@ -11,6 +11,8 @@ // phpcs:ignore WordPress.Security.NonceVerification.Recommended $prpl_active_range = isset( $_GET['range'] ) ? sanitize_text_field( wp_unslash( $_GET['range'] ) ) : '-6 months'; +// phpcs:ignore WordPress.Security.NonceVerification.Recommended +$prpl_active_frequency = isset( $_GET['frequency'] ) ? sanitize_text_field( wp_unslash( $_GET['frequency'] ) ) : 'monthly'; // Arguments for the query. $prpl_query_args = [ @@ -103,7 +105,7 @@ function ( $activity ) { 'dates_params' => [ 'start' => \DateTime::createFromFormat( 'Y-m-d', \gmdate( 'Y-m-01' ) )->modify( $prpl_active_range ), 'end' => new \DateTime(), - 'frequency' => 'weekly', + 'frequency' => $prpl_active_frequency, 'format' => 'M', ], 'chart_params' => [ diff --git a/views/widgets/published-content.php b/views/widgets/published-content.php index 4d6bfa1bc..976114f7c 100644 --- a/views/widgets/published-content.php +++ b/views/widgets/published-content.php @@ -11,6 +11,8 @@ // phpcs:ignore WordPress.Security.NonceVerification.Recommended $prpl_active_range = isset( $_GET['range'] ) ? sanitize_text_field( wp_unslash( $_GET['range'] ) ) : '-6 months'; +// phpcs:ignore WordPress.Security.NonceVerification.Recommended +$prpl_active_frequency = isset( $_GET['frequency'] ) ? sanitize_text_field( wp_unslash( $_GET['frequency'] ) ) : 'monthly'; // Get the content published this week. $prpl_last_week_content = count( @@ -72,7 +74,7 @@ 'dates_params' => [ 'start' => \DateTime::createFromFormat( 'Y-m-d', \gmdate( 'Y-m-01' ) )->modify( $prpl_active_range ), 'end' => new \DateTime(), - 'frequency' => 'weekly', + 'frequency' => $prpl_active_frequency, 'format' => 'M, d', ], 'chart_params' => [ diff --git a/views/widgets/published-pages.php b/views/widgets/published-pages.php index 06314fd47..a6e6f15c1 100644 --- a/views/widgets/published-pages.php +++ b/views/widgets/published-pages.php @@ -9,6 +9,8 @@ // phpcs:ignore WordPress.Security.NonceVerification.Recommended $prpl_active_range = isset( $_GET['range'] ) ? sanitize_text_field( wp_unslash( $_GET['range'] ) ) : '-6 months'; +// phpcs:ignore WordPress.Security.NonceVerification.Recommended +$prpl_active_frequency = isset( $_GET['frequency'] ) ? sanitize_text_field( wp_unslash( $_GET['frequency'] ) ) : 'monthly'; // Get the pages published in the last week. $prpl_last_week_pages = count( @@ -75,7 +77,7 @@ 'dates_params' => [ 'start' => \DateTime::createFromFormat( 'Y-m-d', \gmdate( 'Y-m-01' ) )->modify( $prpl_active_range ), 'end' => new \DateTime(), - 'frequency' => 'monthly', + 'frequency' => $prpl_active_frequency, 'format' => 'M', ], 'chart_params' => [ diff --git a/views/widgets/published-posts.php b/views/widgets/published-posts.php index a5e3ece2e..784018472 100644 --- a/views/widgets/published-posts.php +++ b/views/widgets/published-posts.php @@ -9,6 +9,8 @@ // phpcs:ignore WordPress.Security.NonceVerification.Recommended $prpl_active_range = isset( $_GET['range'] ) ? sanitize_text_field( wp_unslash( $_GET['range'] ) ) : '-6 months'; +// phpcs:ignore WordPress.Security.NonceVerification.Recommended +$prpl_active_frequency = isset( $_GET['frequency'] ) ? sanitize_text_field( wp_unslash( $_GET['frequency'] ) ) : 'monthly'; // Get the posts published in the last week. $prpl_last_week_posts = count( @@ -75,7 +77,7 @@ 'dates_params' => [ 'start' => \DateTime::createFromFormat( 'Y-m-d', \gmdate( 'Y-m-01' ) )->modify( $prpl_active_range ), 'end' => new \DateTime(), - 'frequency' => 'monthly', + 'frequency' => $prpl_active_frequency, 'format' => 'M', ], 'chart_params' => [ diff --git a/views/widgets/published-words.php b/views/widgets/published-words.php index e721724a1..1b1d28dcb 100644 --- a/views/widgets/published-words.php +++ b/views/widgets/published-words.php @@ -11,6 +11,8 @@ // phpcs:ignore WordPress.Security.NonceVerification.Recommended $prpl_active_range = isset( $_GET['range'] ) ? sanitize_text_field( wp_unslash( $_GET['range'] ) ) : '-6 months'; +// phpcs:ignore WordPress.Security.NonceVerification.Recommended +$prpl_active_frequency = isset( $_GET['frequency'] ) ? sanitize_text_field( wp_unslash( $_GET['frequency'] ) ) : 'monthly'; // Arguments for the query. $prpl_query_args = [ @@ -102,7 +104,7 @@ function ( $activity ) { 'dates_params' => [ 'start' => \DateTime::createFromFormat( 'Y-m-d', \gmdate( 'Y-m-01' ) )->modify( $prpl_active_range ), 'end' => new \DateTime(), - 'frequency' => 'monthly', + 'frequency' => $prpl_active_frequency, 'format' => 'M', ], 'chart_params' => [ From a17f460b7ae11df968254c27a21894c8b5fcf47d Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 5 Mar 2024 15:13:15 +0200 Subject: [PATCH 132/490] Add dev to configure the scores --- assets/js/admin.js | 11 ++++++++ includes/activities/class-content.php | 29 ++++++++------------ includes/activities/class-maintenance.php | 9 ++----- includes/class-base.php | 33 +++++++++++++++++++++++ views/admin-page.php | 3 ++- views/widgets/__filter-numbers.php | 24 +++++++++++++++++ views/widgets/activity-scores.php | 2 +- 7 files changed, 84 insertions(+), 27 deletions(-) create mode 100644 views/widgets/__filter-numbers.php diff --git a/assets/js/admin.js b/assets/js/admin.js index f6b46355e..d20756b70 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -150,3 +150,14 @@ document.getElementById( 'prpl-select-frequency' ).addEventListener( 'change', f url.searchParams.set( 'frequency', frequency ); window.location.href = url.href; } ); + +document.getElementById( 'prpl-dev-stats-numbers' ).addEventListener( 'submit', function( event ) { + event.preventDefault(); + const inputs = this.querySelectorAll( 'input' ); + const url = new URL( window.location.href ); + + inputs.forEach( input => { + url.searchParams.set( input.name, input.value ); + } ); + window.location.href = url.href; +} ); diff --git a/includes/activities/class-content.php b/includes/activities/class-content.php index 3e612483a..35b2e09ab 100644 --- a/includes/activities/class-content.php +++ b/includes/activities/class-content.php @@ -16,18 +16,6 @@ */ class Content extends Activity { - /** - * The points awarded for each activity. - * - * @var array - */ - const ACTIVITIES_POINTS = [ - 'publish' => 50, - 'update' => 20, - 'delete' => 10, - 'comment' => 5, - ]; - /** * Category of the activity. * @@ -52,20 +40,25 @@ public function get_post() { * @return int */ public function get_points( $date ) { - $points = self::ACTIVITIES_POINTS[ $this->get_type() ]; - $post = $this->get_post(); + + $dev_config = \progress_planner()->get_dev_config(); + $points = isset( $dev_config[ $this->get_type() ] ) + ? $dev_config[ $this->get_type() ] + : $dev_config['content-publish']; + $post = $this->get_post(); + if ( ! $post ) { return 0; } $words = Content_Helpers::get_word_count( $post->post_content ); if ( $words > 1000 ) { - $points *= 0.8; + $points *= $dev_config['content-1000-plus-words-multiplier']; } elseif ( $words > 350 ) { - $points *= 1.25; + $points *= $dev_config['content-350-plus-words-multiplier']; } elseif ( $words > 100 ) { - $points *= 1.1; + $points *= $dev_config['content-100-plus-words-multiplier']; } else { - $points *= 0.9; + $points *= $dev_config['content-100-minus-words-multiplier']; } $days = absint( Date::get_days_between_dates( $date, $this->get_date() ) ); diff --git a/includes/activities/class-maintenance.php b/includes/activities/class-maintenance.php index 132262f77..9757c75a6 100644 --- a/includes/activities/class-maintenance.php +++ b/includes/activities/class-maintenance.php @@ -51,13 +51,8 @@ public function save() { * @return int */ public function get_points( $date ) { - $points = 2; - if ( str_starts_with( $this->type, 'install_' ) || str_starts_with( $this->type, 'delete_' ) ) { - $points = 1; - } - - // Decay the points based on the age of the activity. - $days = abs( Date::get_days_between_dates( $date, $this->get_date() ) ); + $points = \progress_planner()->get_dev_config( 'maintenance' ); + $days = abs( Date::get_days_between_dates( $date, $this->get_date() ) ); return ( $days < 7 ) ? $points : 0; } diff --git a/includes/class-base.php b/includes/class-base.php index 1a415f87f..c553d212c 100644 --- a/includes/class-base.php +++ b/includes/class-base.php @@ -65,4 +65,37 @@ public function get_query() { public function get_badges() { return new Badges(); } + + /** + * THIS SHOULD BE DELETED. + * WE ONLY HAVE IT HERE TO EXPERIMENT WITH THE NUMBERS + * WE'LL HAVE TO USE FOR STATS/SCORES. + * + * TODO: DELETE THIS METHOD. + * + * @param string $param The parameter to get. Null to get all. + * + * @return mixed + */ + public function get_dev_config( $param = null ) { + $config = [ + 'content-publish' => 50, + 'content-update' => 10, + 'content-delete' => 5, + 'content-100-minus-words-multiplier' => 0.8, + 'content-100-plus-words-multiplier' => 1.1, + 'content-350-plus-words-multiplier' => 1.25, + 'content-1000-plus-words-multiplier' => 0.8, + 'maintenance' => 10, + 'activity-score-target' => 200, + ]; + + // phpcs:disable WordPress.Security + foreach ( $config as $key => $value ) { + $config[ $key ] = isset( $_GET[ $key ] ) ? (float) $_GET[ $key ] : $value; + } + // phpcs:enable WordPress.Security + + return null === $param ? $config : $config[ $param ]; + } } diff --git a/views/admin-page.php b/views/admin-page.php index 19a47d13e..25e3d23cd 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -29,12 +29,13 @@ 'website-activity-score', 'published-content', 'activity-scores', - 'latest-badge', + // 'latest-badge', 'published-pages', 'published-posts', 'published-content-density', 'published-words', 'badges-progress', + '__filter-numbers', ] as $prpl_widget ) { echo '
'; include "widgets/{$prpl_widget}.php"; diff --git a/views/widgets/__filter-numbers.php b/views/widgets/__filter-numbers.php new file mode 100644 index 000000000..081133f22 --- /dev/null +++ b/views/widgets/__filter-numbers.php @@ -0,0 +1,24 @@ +get_dev_config(); +?> +

DEV - Weights, scores, multipliers

+
+ $value ) : ?> + +
+ + +
diff --git a/views/widgets/activity-scores.php b/views/widgets/activity-scores.php index c6d339e64..6dae03231 100644 --- a/views/widgets/activity-scores.php +++ b/views/widgets/activity-scores.php @@ -52,7 +52,7 @@ foreach ( $activities as $activity ) { $score += $activity->get_points( $date ); } - $target = 200; // 200 points is 4 posts per week. + $target = \progress_planner()->get_dev_config( 'activity-score-target' ); return round( min( 100, ( $score / $target ) * 100 ) ); }, 'additive' => false, From 5a715b68a175c5bbe11000ae81a671240ec5dbcb Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 6 Mar 2024 10:03:19 +0200 Subject: [PATCH 133/490] fix JS error when there are no events yet --- assets/js/admin.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/assets/js/admin.js b/assets/js/admin.js index d20756b70..5c3af3b35 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -151,13 +151,15 @@ document.getElementById( 'prpl-select-frequency' ).addEventListener( 'change', f window.location.href = url.href; } ); -document.getElementById( 'prpl-dev-stats-numbers' ).addEventListener( 'submit', function( event ) { - event.preventDefault(); - const inputs = this.querySelectorAll( 'input' ); - const url = new URL( window.location.href ); - - inputs.forEach( input => { - url.searchParams.set( input.name, input.value ); +if ( document.getElementById( 'prpl-dev-stats-numbers' ) ) { + document.getElementById( 'prpl-dev-stats-numbers' ).addEventListener( 'submit', function( event ) { + event.preventDefault(); + const inputs = this.querySelectorAll( 'input' ); + const url = new URL( window.location.href ); + + inputs.forEach( input => { + url.searchParams.set( input.name, input.value ); + } ); + window.location.href = url.href; } ); - window.location.href = url.href; -} ); +} From aed480be808906ed43958b4acb51719c5ce91e30 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 6 Mar 2024 12:13:57 +0200 Subject: [PATCH 134/490] bugfix --- includes/admin/class-dashboard-widget.php | 10 +--------- views/admin-page.php | 9 +-------- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/includes/admin/class-dashboard-widget.php b/includes/admin/class-dashboard-widget.php index 2d4a1324e..7495fe7cd 100644 --- a/includes/admin/class-dashboard-widget.php +++ b/includes/admin/class-dashboard-widget.php @@ -34,15 +34,7 @@ public function add_dashboard_widget() { * Render the dashboard widget. */ public function render_dashboard_widget() { - $scan_pending = empty( - \progress_planner()->get_query()->query_activities( - [ - 'category' => 'content', - 'type' => 'publish', - ] - ) - ); - + $scan_pending = empty( \progress_planner()->get_query()->query_activities( [] ) ); ?>
diff --git a/views/admin-page.php b/views/admin-page.php index 25e3d23cd..4f129113b 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -7,14 +7,7 @@ namespace ProgressPlanner; -$prpl_scan_pending = empty( - \progress_planner()->get_query()->query_activities( - [ - 'category' => 'content', - 'type' => 'publish', - ] - ) -); +$prpl_scan_pending = empty( \progress_planner()->get_query()->query_activities( [] ) ); ?>

From c9a589e7987a2a427a35fd17bdae933d84d5b49e Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 6 Mar 2024 13:02:56 +0200 Subject: [PATCH 135/490] Simplify words count calculation --- includes/activities/class-content-helpers.php | 43 ------------------- views/widgets/published-content-density.php | 15 +++---- views/widgets/published-words.php | 15 +++---- 3 files changed, 14 insertions(+), 59 deletions(-) diff --git a/includes/activities/class-content-helpers.php b/includes/activities/class-content-helpers.php index 1ccdcccb5..0ea3c222f 100644 --- a/includes/activities/class-content-helpers.php +++ b/includes/activities/class-content-helpers.php @@ -67,47 +67,4 @@ public static function get_activity_from_post( $post ) { $activity->set_user_id( $post->post_author ); return $activity; } - - /** - * Get posts by dates. - * - * @param array $query_args The query arguments. See WP_Query for more details. - * - * @return array - */ - private static function get_posts_stats_by_query( $query_args ) { - $key = md5( wp_json_encode( $query_args ) ); - static $cached = []; - if ( ! isset( $cached[ $key ] ) ) { - $cached[ $key ] = get_posts( - wp_parse_args( - $query_args, - [ 'posts_per_page' => -1 ] - ) - ); - } - - $posts = $cached[ $key ]; - - return [ - 'count' => count( $posts ), - 'words' => array_sum( array_map( [ __CLASS__, 'get_word_count' ], wp_list_pluck( $posts, 'post_content' ) ) ), - ]; - } - - /** - * Get posts stats from an array of post-IDs. - * - * @param int[] $post_ids The post-IDs. - * - * @return array - */ - public static function get_posts_stats_by_ids( $post_ids ) { - return self::get_posts_stats_by_query( - [ - 'post__in' => $post_ids, - 'posts_per_page' => count( $post_ids ), - ] - ); - } } diff --git a/views/widgets/published-content-density.php b/views/widgets/published-content-density.php index c0c90f1c0..db9cda26a 100644 --- a/views/widgets/published-content-density.php +++ b/views/widgets/published-content-density.php @@ -28,14 +28,13 @@ * @return int */ $prpl_count_words_callback = function ( $activities ) { - return Content_Helpers::get_posts_stats_by_ids( - array_map( - function ( $activity ) { - return $activity->get_data_id(); - }, - $activities - ) - )['words']; + $words = 0; + foreach ( $activities as $activity ) { + $words += Content_Helpers::get_word_count( + $activity->get_post()->post_content + ); + } + return $words; }; /** diff --git a/views/widgets/published-words.php b/views/widgets/published-words.php index 1b1d28dcb..f8ef975a7 100644 --- a/views/widgets/published-words.php +++ b/views/widgets/published-words.php @@ -28,14 +28,13 @@ * @return int */ $prpl_count_words_callback = function ( $activities ) { - return Content_Helpers::get_posts_stats_by_ids( - array_map( - function ( $activity ) { - return $activity->get_data_id(); - }, - $activities - ) - )['words']; + $words = 0; + foreach ( $activities as $activity ) { + $words += Content_Helpers::get_word_count( + $activity->get_post()->post_content + ); + } + return $words; }; // Get the all-time words count. From 1485fb419c6906366a1f58b29e0b3a41bb992020 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 6 Mar 2024 13:52:42 +0200 Subject: [PATCH 136/490] bugfix --- includes/class-badges.php | 6 +++++- includes/class-chart.php | 27 +++++++++++++++------------ includes/class-query.php | 6 +++++- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/includes/class-badges.php b/includes/class-badges.php index 41fbbb080..fd1868288 100644 --- a/includes/class-badges.php +++ b/includes/class-badges.php @@ -206,6 +206,10 @@ private function register_badges() { ], ], 'progress_callback' => function ( $target ) { + $oldest_activity = \progress_planner()->get_query()->get_oldest_activity(); + if ( null === $oldest_activity ) { + return 0; + } $goal = new Goal_Recurring( new Goal_Posts( [ @@ -229,7 +233,7 @@ private function register_badges() { ] ), 'weekly', - \progress_planner()->get_query()->get_oldest_activity()->get_date(), // Beginning of the stats. + $oldest_activity->get_date(), // Beginning of the stats. new \DateTime() // Today. ); diff --git a/includes/class-chart.php b/includes/class-chart.php index b25d51925..0762d90fc 100644 --- a/includes/class-chart.php +++ b/includes/class-chart.php @@ -98,19 +98,22 @@ public function the_chart( $args = [] ) { // Calculate zero stats to be used as the baseline. $score = 0; if ( $args['additive'] ) { - $activities = \progress_planner()->get_query()->query_activities( - array_merge( - $args['query_params'], - [ - 'start_date' => \progress_planner()->get_query()->get_oldest_activity()->get_date(), - 'end_date' => $periods[0]['dates'][0]->modify( '-1 day' ), - ] - ) - ); - if ( $args['filter_results'] ) { - $activities = $args['filter_results']( $activities ); + $oldest_activity = \progress_planner()->get_query()->get_oldest_activity(); + if ( null !== $oldest_activity ) { + $activities = \progress_planner()->get_query()->query_activities( + array_merge( + $args['query_params'], + [ + 'start_date' => $oldest_activity->get_date(), + 'end_date' => $periods[0]['dates'][0]->modify( '-1 day' ), + ] + ) + ); + if ( $args['filter_results'] ) { + $activities = $args['filter_results']( $activities ); + } + $score = $args['count_callback']( $activities ); } - $score = $args['count_callback']( $activities ); } foreach ( $periods as $period ) { diff --git a/includes/class-query.php b/includes/class-query.php index 0b503aa59..93f179974 100644 --- a/includes/class-query.php +++ b/includes/class-query.php @@ -358,7 +358,7 @@ public function delete_category_activities( $category ) { /** * Get oldest activity. * - * @return \ProgressPlanner\Activity + * @return \ProgressPlanner\Activity|null Returns null if there are no activities. */ public function get_oldest_activity() { global $wpdb; @@ -371,6 +371,10 @@ public function get_oldest_activity() { ) ); + if ( empty( $results ) ) { + return null; + } + $class_name = $this->get_activity_class_name( $result->category ); $activity = new $class_name(); $activity->set_date( new \DateTime( $result->date ) ); From 1dc743f83a964a0c327123e8d9be59577d8cf893 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 6 Mar 2024 14:03:32 +0200 Subject: [PATCH 137/490] performance tweak --- views/admin-page.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/views/admin-page.php b/views/admin-page.php index 4f129113b..a3fe9baa6 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -6,8 +6,7 @@ */ namespace ProgressPlanner; - -$prpl_scan_pending = empty( \progress_planner()->get_query()->query_activities( [] ) ); +$prpl_scan_pending = empty( \progress_planner()->get_query()->get_oldest_activity() ); ?>

From 956476352f44b1e56758b3cb70dc145fb8db91c0 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 6 Mar 2024 14:19:12 +0200 Subject: [PATCH 138/490] bugfix for maintenance activities tracking --- includes/scan/class-maintenance.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/includes/scan/class-maintenance.php b/includes/scan/class-maintenance.php index d23147910..13dc97cd3 100644 --- a/includes/scan/class-maintenance.php +++ b/includes/scan/class-maintenance.php @@ -82,16 +82,9 @@ public function on_upgrade( $upgrader, $options ) { /** * On delete plugin. * - * @param string $plugin The plugin. - * @param bool $deleted Whether the plugin was deleted. - * * @return void */ - public function on_delete_plugin( $plugin, $deleted ) { - if ( ! $deleted ) { - return; - } - + public function on_delete_plugin() { $activity = new Activity_Maintenance(); $activity->set_type( 'delete_plugin' ); $activity->save(); @@ -105,11 +98,7 @@ public function on_delete_plugin( $plugin, $deleted ) { * * @return void */ - public function on_delete_theme( $theme, $deleted ) { - if ( ! $deleted ) { - return; - } - + public function on_delete_theme() { $activity = new Activity_Maintenance(); $activity->set_type( 'delete_theme' ); $activity->save(); @@ -158,4 +147,15 @@ public function on_switch_theme() { protected function get_update_type( $options ) { return isset( $options['type'] ) ? $options['type'] : 'unknown'; } + + /** + * Get the type of the install. + * + * @param array $options The options. + * + * @return string + */ + protected function get_install_type( $options ) { + return isset( $options['type'] ) ? $options['type'] : 'unknown'; + } } From 4e0187dfed61f547d5d05972bb48e34316d658f8 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 6 Mar 2024 14:46:20 +0200 Subject: [PATCH 139/490] bugfix for Query --- includes/class-query.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-query.php b/includes/class-query.php index 93f179974..f8daa3d79 100644 --- a/includes/class-query.php +++ b/includes/class-query.php @@ -371,7 +371,7 @@ public function get_oldest_activity() { ) ); - if ( empty( $results ) ) { + if ( ! $result ) { return null; } From f1de2e06acb610238c7f73f39e26b296ec9355eb Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 6 Mar 2024 15:21:52 +0200 Subject: [PATCH 140/490] Reduce calls to count words in posts --- includes/activities/class-content-helpers.php | 16 +++++++++++++--- includes/activities/class-content.php | 2 +- views/widgets/published-content-density.php | 3 ++- views/widgets/published-words.php | 3 ++- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/includes/activities/class-content-helpers.php b/includes/activities/class-content-helpers.php index 0ea3c222f..918abbbbb 100644 --- a/includes/activities/class-content-helpers.php +++ b/includes/activities/class-content-helpers.php @@ -37,15 +37,25 @@ public static function get_post_types_names() { * * @return int */ - public static function get_word_count( $content ) { + public static function get_word_count( $content, $post_id = 0 ) { + static $counts = []; + if ( $post_id && isset( $counts[ $post_id ] ) ) { + return $counts[ $post_id ]; + } + // Parse blocks and shortcodes. $content = \do_blocks( \do_shortcode( $content ) ); // Strip HTML. $content = \wp_strip_all_tags( $content, true ); - // Count words. - return \str_word_count( $content ); + $count = \str_word_count( $content ); + + if ( $post_id ) { + $counts[ $post_id ] = $count; + } + + return $count; } /** diff --git a/includes/activities/class-content.php b/includes/activities/class-content.php index 35b2e09ab..b1d7860d8 100644 --- a/includes/activities/class-content.php +++ b/includes/activities/class-content.php @@ -50,7 +50,7 @@ public function get_points( $date ) { if ( ! $post ) { return 0; } - $words = Content_Helpers::get_word_count( $post->post_content ); + $words = Content_Helpers::get_word_count( $post->post_content, $post->ID ); if ( $words > 1000 ) { $points *= $dev_config['content-1000-plus-words-multiplier']; } elseif ( $words > 350 ) { diff --git a/views/widgets/published-content-density.php b/views/widgets/published-content-density.php index db9cda26a..ff5355460 100644 --- a/views/widgets/published-content-density.php +++ b/views/widgets/published-content-density.php @@ -31,7 +31,8 @@ $words = 0; foreach ( $activities as $activity ) { $words += Content_Helpers::get_word_count( - $activity->get_post()->post_content + $activity->get_post()->post_content, + $activity->get_data_id() ); } return $words; diff --git a/views/widgets/published-words.php b/views/widgets/published-words.php index f8ef975a7..fad3f7476 100644 --- a/views/widgets/published-words.php +++ b/views/widgets/published-words.php @@ -31,7 +31,8 @@ $words = 0; foreach ( $activities as $activity ) { $words += Content_Helpers::get_word_count( - $activity->get_post()->post_content + $activity->get_post()->post_content, + $activity->get_data_id() ); } return $words; From 06bca9934be00c35f4340a334437da2fc2828802 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 7 Mar 2024 09:20:46 +0200 Subject: [PATCH 141/490] another bugfix --- views/admin-page.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/views/admin-page.php b/views/admin-page.php index a3fe9baa6..a7aa793b3 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -6,7 +6,8 @@ */ namespace ProgressPlanner; -$prpl_scan_pending = empty( \progress_planner()->get_query()->get_oldest_activity() ); + +$prpl_scan_pending = null === \progress_planner()->get_query()->get_oldest_activity(); ?>

From 4d67fcb3c3125ae7742d54e75b24a11c1fc51c68 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 7 Mar 2024 10:05:12 +0200 Subject: [PATCH 142/490] change the way normalized scores are calculated --- includes/class-chart.php | 60 ++++++++++++++++++++++++++-------------- includes/class-date.php | 2 +- 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/includes/class-chart.php b/includes/class-chart.php index 0762d90fc..49116d938 100644 --- a/includes/class-chart.php +++ b/includes/class-chart.php @@ -100,12 +100,14 @@ public function the_chart( $args = [] ) { if ( $args['additive'] ) { $oldest_activity = \progress_planner()->get_query()->get_oldest_activity(); if ( null !== $oldest_activity ) { + $end_date = clone $periods[0]['dates'][0]; + $end_date->modify( '-1 day' ); $activities = \progress_planner()->get_query()->query_activities( array_merge( $args['query_params'], [ 'start_date' => $oldest_activity->get_date(), - 'end_date' => $periods[0]['dates'][0]->modify( '-1 day' ), + 'end_date' => $end_date, ] ) ); @@ -116,25 +118,36 @@ public function the_chart( $args = [] ) { } } + $previous_month_activities = []; + if ( $args['normalized'] ) { + $previous_month_start = clone $periods[0]['start']; + $previous_month_start->modify( '-1 month' ); + $previous_month_end = clone $periods[0]['start']; + $previous_month_end->modify( '-1 day' ); + $previous_month_activities = \progress_planner()->get_query()->query_activities( + array_merge( + $args['query_params'], + [ + 'start_date' => $previous_month_start, + 'end_date' => $previous_month_end, + ] + ) + ); + if ( $args['filter_results'] ) { + $activities = $args['filter_results']( $activities ); + } + } + foreach ( $periods as $period ) { - $activities = $args['normalized'] - ? \progress_planner()->get_query()->query_activities( - array_merge( - $args['query_params'], - [ - 'start_date' => $period['start']->modify( '-31 days' ), - 'end_date' => $period['end'], - ] - ) - ) : \progress_planner()->get_query()->query_activities( - array_merge( - $args['query_params'], - [ - 'start_date' => $period['start'], - 'end_date' => $period['end'], - ] - ) - ); + $activities = \progress_planner()->get_query()->query_activities( + array_merge( + $args['query_params'], + [ + 'start_date' => $period['start'], + 'end_date' => $period['end'], + ] + ) + ); if ( $args['filter_results'] ) { $activities = $args['filter_results']( $activities ); } @@ -142,7 +155,14 @@ public function the_chart( $args = [] ) { $data['labels'][] = $period['dates'][0]->format( $args['dates_params']['format'] ); $period_score = $args['count_callback']( $activities, $period['start'] ); - $score = $args['additive'] ? $score + $period_score : $period_score; + if ( $args['normalized'] ) { + // Add the previous month activities to the current month score. + $period_score += $args['count_callback']( $previous_month_activities, $period['start'] ); + // Update the previous month activities for the next iteration of the loop. + $previous_month_activities = $activities; + } + + $score = $args['additive'] ? $score + $period_score : $period_score; $datasets[0]['data'][] = $score; $datasets[0]['backgroundColor'][] = $args['colors']['background']( $score ); diff --git a/includes/class-date.php b/includes/class-date.php index bddc3cc2f..6dcf4a239 100644 --- a/includes/class-date.php +++ b/includes/class-date.php @@ -43,7 +43,7 @@ public static function get_range( $start, $end ) { * @return array */ public static function get_periods( $start, $end, $frequency ) { - $end = $end->modify( '+1 day' ); + $end->modify( '+1 day' ); switch ( $frequency ) { case 'daily': From b0b51e1197e86efcc2668f2eeafb8f8be2d1e5cc Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 7 Mar 2024 10:40:23 +0200 Subject: [PATCH 143/490] Implement badges --- includes/class-badges.php | 141 ++++++++++++++++++++------------------ includes/class-base.php | 15 ++++ includes/class-query.php | 4 ++ 3 files changed, 93 insertions(+), 67 deletions(-) diff --git a/includes/class-badges.php b/includes/class-badges.php index fd1868288..7b31831cd 100644 --- a/includes/class-badges.php +++ b/includes/class-badges.php @@ -9,6 +9,7 @@ use ProgressPlanner\Goals\Goal_Recurring; use ProgressPlanner\Goals\Goal_Posts; +use ProgressPlanner\Base; /** * Badges class. @@ -111,105 +112,111 @@ public function get_badge_progress( $badge_id ) { private function register_badges() { // Badges for number of posts. $this->register_badge( - 'content_published_count', + 'content_writing', [ 'steps' => [ [ - 'target' => 100, - 'name' => __( '100 Posts', 'progress-planner' ), + 'target' => 'wonderful-writer', + 'name' => __( 'Wonderful Writer', 'progress-planner' ), 'icon' => '🏆', ], [ - 'target' => 1000, - 'name' => __( '1000 Posts', 'progress-planner' ), + 'target' => 'awesome-author', + 'name' => __( 'Awesome Author', 'progress-planner' ), 'icon' => '🏆', ], [ - 'target' => 2000, - 'name' => __( '2000 Posts', 'progress-planner' ), - 'icon' => '🏆', - ], - [ - 'target' => 5000, - 'name' => __( '5000 Posts', 'progress-planner' ), + 'target' => 'notorious-novelist', + 'name' => __( 'Notorious Novelist', 'progress-planner' ), 'icon' => '🏆', ], ], 'progress_callback' => function ( $target ) { - $activities = \progress_planner()->get_query()->query_activities( - [ - 'category' => 'content', - 'type' => 'publish', - ] - ); - return min( floor( 100 * count( $activities ) / $target ), 100 ); - }, - ] - ); + // Evaluation for the "Wonderful writer" badge. + if ( 'wonderful-writer' === $target ) { + $existing_count = count( + \progress_planner()->get_query()->query_activities( + [ + 'category' => 'content', + 'type' => 'publish', + ] + ) + ); + // Targeting 200 existing posts. + $existing_progress = max( 100, floor( $existing_count / 2 ) ); + if ( 100 <= $existing_progress ) { + return 100; + } + $new_count = count( + \progress_planner()->get_query()->query_activities( + [ + 'category' => 'content', + 'type' => 'publish', + 'start_date' => Base::get_activation_date(), + ], + ) + ); + // Targeting 10 new posts. + $new_progress = max( 100, floor( $new_count * 10 ) ); + + return max( $existing_progress, $new_progress ); + } - // 100 maintenance tasks. - $this->register_badge( - 'maintenance_tasks', - [ - 'steps' => [ - [ - 'target' => 10, - 'name' => __( '10 maintenance tasks', 'progress-planner' ), - 'icon' => '🏆', - ], - [ - 'target' => 100, - 'name' => __( '100 maintenance tasks', 'progress-planner' ), - 'icon' => '🏆', - ], - [ - 'target' => 1000, - 'name' => __( '1000 maintenance tasks', 'progress-planner' ), - 'icon' => '🏆', - ], - ], - 'progress_callback' => function ( $target ) { - $activities = \progress_planner()->get_query()->query_activities( - [ - 'category' => 'maintenance', - ] - ); - return min( floor( 100 * count( $activities ) / $target ), 100 ); + // Evaluation for the "Awesome author" badge. + if ( 'awesome-author' === $target ) { + $new_count = count( + \progress_planner()->get_query()->query_activities( + [ + 'category' => 'content', + 'type' => 'publish', + 'start_date' => Base::get_activation_date(), + ], + ) + ); + // Targeting 30 new posts. + return min( 100, floor( 100 * $new_count / 30 ) ); + } + + // Evaluation for the "Notorious novelist" badge. + if ( 'notorious-novelist' === $target ) { + $new_count = count( + \progress_planner()->get_query()->query_activities( + [ + 'category' => 'content', + 'type' => 'publish', + 'start_date' => Base::get_activation_date(), + ], + ) + ); + // Targeting 50 new posts. + return min( 100, floor( 50 * $new_count / 100 ) ); + } }, ] ); // Write a post for 10 consecutive weeks. $this->register_badge( - 'consecutive_weeks_posts', + 'streak_any_task', [ 'steps' => [ [ - 'target' => 10, - 'name' => __( '10 weeks posting streak', 'progress-planner' ), - 'icon' => '🏆', - ], - [ - 'target' => 52, - 'name' => __( '52 weeks posting streak', 'progress-planner' ), + 'target' => 6, + 'name' => __( 'Progress Professional', 'progress-planner' ), 'icon' => '🏆', ], [ - 'target' => 104, - 'name' => __( '104 weeks posting streak', 'progress-planner' ), + 'target' => 26, + 'name' => __( 'Maintenance Maniac', 'progress-planner' ), 'icon' => '🏆', ], [ - 'target' => 208, - 'name' => __( '208 weeks posting streak', 'progress-planner' ), + 'target' => 52, + 'name' => __( 'Super Site Specialist', 'progress-planner' ), 'icon' => '🏆', ], ], 'progress_callback' => function ( $target ) { - $oldest_activity = \progress_planner()->get_query()->get_oldest_activity(); - if ( null === $oldest_activity ) { - return 0; - } $goal = new Goal_Recurring( new Goal_Posts( [ @@ -233,7 +240,7 @@ private function register_badges() { ] ), 'weekly', - $oldest_activity->get_date(), // Beginning of the stats. + Base::get_activation_date(), new \DateTime() // Today. ); diff --git a/includes/class-base.php b/includes/class-base.php index c553d212c..65028002f 100644 --- a/includes/class-base.php +++ b/includes/class-base.php @@ -66,6 +66,21 @@ public function get_badges() { return new Badges(); } + /** + * Get the activation date. + * + * @return \DateTime + */ + public static function get_activation_date() { + $activation_date = get_option( 'progress_planner_activation_date' ); + if ( ! $activation_date ) { + $activation_date = new \DateTime(); + update_option( 'progress_planner_activation_date', $activation_date->format( 'Y-m-d' ) ); + return $activation_date; + } + return \DateTime::createFromFormat( 'Y-m-d', $activation_date ); + } + /** * THIS SHOULD BE DELETED. * WE ONLY HAVE IT HERE TO EXPERIMENT WITH THE NUMBERS diff --git a/includes/class-query.php b/includes/class-query.php index f8daa3d79..f78da9ab3 100644 --- a/includes/class-query.php +++ b/includes/class-query.php @@ -174,6 +174,10 @@ public function query_activities( $args, $return_type = 'ACTIVITIES' ) { wp_cache_set( $cache_key, $results ); } + if ( ! $results ) { + return []; + } + return 'RAW' === $return_type ? $results : $this->get_activities_from_results( $results ); From 8ec723ccce4a50c88bf252e4e0e22fa0ded58ebd Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 7 Mar 2024 10:54:30 +0200 Subject: [PATCH 144/490] fix for activity-scores chart --- includes/class-chart.php | 5 ++++- views/widgets/activity-scores.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/includes/class-chart.php b/includes/class-chart.php index 49116d938..018761064 100644 --- a/includes/class-chart.php +++ b/includes/class-chart.php @@ -56,6 +56,7 @@ public function the_chart( $args = [] ) { 'count_callback' => function ( $activities, $date = null ) { return count( $activities ); }, + 'max' => null, ] ); $args['chart_params'] = wp_parse_args( @@ -164,7 +165,9 @@ public function the_chart( $args = [] ) { $score = $args['additive'] ? $score + $period_score : $period_score; - $datasets[0]['data'][] = $score; + $datasets[0]['data'][] = null === $args['max'] + ? $score + : min( $score, $args['max'] ); $datasets[0]['backgroundColor'][] = $args['colors']['background']( $score ); $datasets[0]['borderColor'][] = $args['colors']['border']( $score ); } diff --git a/views/widgets/activity-scores.php b/views/widgets/activity-scores.php index 6dae03231..df40abaa5 100644 --- a/views/widgets/activity-scores.php +++ b/views/widgets/activity-scores.php @@ -53,7 +53,7 @@ $score += $activity->get_points( $date ); } $target = \progress_planner()->get_dev_config( 'activity-score-target' ); - return round( min( 100, ( $score / $target ) * 100 ) ); + return $score / $target; }, 'additive' => false, 'normalized' => true, From 3f224ae5519fcae0be74d3dee264e3acb41156ec Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 7 Mar 2024 11:08:27 +0200 Subject: [PATCH 145/490] Allow breaks in streaks --- includes/class-badges.php | 3 ++- includes/goals/class-goal-recurring.php | 29 +++++++++++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/includes/class-badges.php b/includes/class-badges.php index 7b31831cd..dfdaa8dda 100644 --- a/includes/class-badges.php +++ b/includes/class-badges.php @@ -241,7 +241,8 @@ private function register_badges() { ), 'weekly', Base::get_activation_date(), - new \DateTime() // Today. + new \DateTime(), // Today. + 1 // Allow break in the streak for 1 week. ); return min( floor( 100 * $goal->get_streak()['max_streak'] / $target ), 100 ); diff --git a/includes/goals/class-goal-recurring.php b/includes/goals/class-goal-recurring.php index bab4dcf61..fef177ba5 100644 --- a/includes/goals/class-goal-recurring.php +++ b/includes/goals/class-goal-recurring.php @@ -42,6 +42,13 @@ class Goal_Recurring { */ private $end; + /** + * The number of breaks in the streak that are allowed. + * + * @var int + */ + private $allowed_break = 0; + /** * An array of occurences. * @@ -54,14 +61,16 @@ class Goal_Recurring { * * @param \ProgressPlanner\Goals\Goal $goal The goal object. * @param string $frequency The goal frequency. - * @param int|string $start The start date. - * @param int|string $end The end date. + * @param \DateTime $start The start date. + * @param \DateTime $end The end date. + * @param int $allowed_break The number of breaks in the streak that are allowed. */ - public function __construct( $goal, $frequency, $start, $end ) { - $this->goal = $goal; - $this->frequency = $frequency; - $this->start = $start; - $this->end = $end; + public function __construct( $goal, $frequency, $start, $end, $allowed_break = 0 ) { + $this->goal = $goal; + $this->frequency = $frequency; + $this->start = $start; + $this->end = $end; + $this->allowed_break = $allowed_break; } /** @@ -136,6 +145,12 @@ public function get_streak() { $max_streak = max( $max_streak, $streak_nr ); continue; } + + if ( $this->allowed_break > 0 ) { + --$this->allowed_break; + continue; + } + $streak_nr = 0; } From 75a30e983b6ed1a6ac22ad0167d17208f0c891d1 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 7 Mar 2024 11:08:48 +0200 Subject: [PATCH 146/490] cap activity scores at 100 --- views/widgets/activity-scores.php | 1 + 1 file changed, 1 insertion(+) diff --git a/views/widgets/activity-scores.php b/views/widgets/activity-scores.php index df40abaa5..8ae72bf48 100644 --- a/views/widgets/activity-scores.php +++ b/views/widgets/activity-scores.php @@ -61,6 +61,7 @@ 'background' => $prpl_color_callback, 'border' => $prpl_color_callback, ], + 'max' => 100, ] ); ?> From de3d90df08f257ae7f738568c1a9eee69a1722cb Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 7 Mar 2024 11:31:27 +0200 Subject: [PATCH 147/490] bugfix --- includes/class-date.php | 3 +++ includes/goals/class-goal-recurring.php | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/includes/class-date.php b/includes/class-date.php index 6dcf4a239..d59fa24f9 100644 --- a/includes/class-date.php +++ b/includes/class-date.php @@ -70,6 +70,9 @@ public static function get_periods( $start, $end, $frequency ) { $date_ranges[] = static::get_range( $date, $period[ $key + 1 ] ); } } + if ( empty( $date_ranges ) ) { + return []; + } if ( $end->format( 'z' ) !== end( $date_ranges )['end']->format( 'z' ) ) { $date_ranges[] = static::get_range( end( $date_ranges )['end'], $end ); } diff --git a/includes/goals/class-goal-recurring.php b/includes/goals/class-goal-recurring.php index fef177ba5..6c05eab66 100644 --- a/includes/goals/class-goal-recurring.php +++ b/includes/goals/class-goal-recurring.php @@ -94,6 +94,10 @@ public function get_occurences() { $date = new Date(); $ranges = $date->get_periods( $this->start, $this->end, $this->frequency ); + if ( empty( $ranges ) ) { + return $this->occurences; + } + // If the last range ends before today, add a new range. if ( (int) gmdate( 'Ymd' ) > (int) end( $ranges )['end']->format( 'Ymd' ) ) { $ranges[] = $date->get_range( From 5b6074beb4d763ee1fec71b735886c4adf65143c Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 8 Mar 2024 08:56:58 +0200 Subject: [PATCH 148/490] fix chart periods dates --- includes/class-chart.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/includes/class-chart.php b/includes/class-chart.php index 018761064..7753c537e 100644 --- a/includes/class-chart.php +++ b/includes/class-chart.php @@ -101,8 +101,7 @@ public function the_chart( $args = [] ) { if ( $args['additive'] ) { $oldest_activity = \progress_planner()->get_query()->get_oldest_activity(); if ( null !== $oldest_activity ) { - $end_date = clone $periods[0]['dates'][0]; - $end_date->modify( '-1 day' ); + $end_date = clone $periods[0]['dates'][0]; $activities = \progress_planner()->get_query()->query_activities( array_merge( $args['query_params'], @@ -123,8 +122,7 @@ public function the_chart( $args = [] ) { if ( $args['normalized'] ) { $previous_month_start = clone $periods[0]['start']; $previous_month_start->modify( '-1 month' ); - $previous_month_end = clone $periods[0]['start']; - $previous_month_end->modify( '-1 day' ); + $previous_month_end = clone $periods[0]['start']; $previous_month_activities = \progress_planner()->get_query()->query_activities( array_merge( $args['query_params'], @@ -145,7 +143,7 @@ public function the_chart( $args = [] ) { $args['query_params'], [ 'start_date' => $period['start'], - 'end_date' => $period['end'], + 'end_date' => $period['end']->modify( '-1 day' ), ] ) ); From 58fb9de37d81b94b725b121837ce5310e2c3299a Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 8 Mar 2024 08:57:07 +0200 Subject: [PATCH 149/490] reset stats --- includes/scan/class-content.php | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/scan/class-content.php b/includes/scan/class-content.php index 1cdb1c879..dbc395ad5 100644 --- a/includes/scan/class-content.php +++ b/includes/scan/class-content.php @@ -291,6 +291,7 @@ public static function update_stats() { */ public static function reset_stats() { \progress_planner()->get_query()->delete_category_activities( 'content' ); + \progress_planner()->get_query()->delete_category_activities( 'maintenance' ); \delete_option( static::LAST_SCANNED_PAGE_OPTION ); } From ad2d4a17c049836c800509962f39e1be05e58707 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 8 Mar 2024 10:34:38 +0200 Subject: [PATCH 150/490] more dates fixes --- includes/class-chart.php | 5 +++-- includes/class-date.php | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/includes/class-chart.php b/includes/class-chart.php index 7753c537e..75b32fe05 100644 --- a/includes/class-chart.php +++ b/includes/class-chart.php @@ -101,7 +101,8 @@ public function the_chart( $args = [] ) { if ( $args['additive'] ) { $oldest_activity = \progress_planner()->get_query()->get_oldest_activity(); if ( null !== $oldest_activity ) { - $end_date = clone $periods[0]['dates'][0]; + $end_date = clone $args['dates_params']['start']; + $end_date->modify( '-1 day' ); $activities = \progress_planner()->get_query()->query_activities( array_merge( $args['query_params'], @@ -143,7 +144,7 @@ public function the_chart( $args = [] ) { $args['query_params'], [ 'start_date' => $period['start'], - 'end_date' => $period['end']->modify( '-1 day' ), + 'end_date' => $period['end'], ] ) ); diff --git a/includes/class-date.php b/includes/class-date.php index d59fa24f9..3d6fa1c17 100644 --- a/includes/class-date.php +++ b/includes/class-date.php @@ -74,7 +74,8 @@ public static function get_periods( $start, $end, $frequency ) { return []; } if ( $end->format( 'z' ) !== end( $date_ranges )['end']->format( 'z' ) ) { - $date_ranges[] = static::get_range( end( $date_ranges )['end'], $end ); + $final_end = clone end( $date_ranges )['end']; + $date_ranges[] = static::get_range( $final_end->modify( '+1 day' ), $end ); } return $date_ranges; From 41ad45a8726635ec0175185158d1a86d260d5a32 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 8 Mar 2024 10:35:57 +0200 Subject: [PATCH 151/490] Format numbers --- views/widgets/published-content-density.php | 10 +++++----- views/widgets/published-content.php | 10 +++++----- views/widgets/published-pages.php | 8 ++++---- views/widgets/published-posts.php | 10 +++++----- views/widgets/published-words.php | 10 +++++----- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/views/widgets/published-content-density.php b/views/widgets/published-content-density.php index ff5355460..17ab5ea25 100644 --- a/views/widgets/published-content-density.php +++ b/views/widgets/published-content-density.php @@ -75,7 +75,7 @@
- + @@ -85,10 +85,10 @@

diff --git a/views/widgets/published-content.php b/views/widgets/published-content.php index 976114f7c..b1f85cf18 100644 --- a/views/widgets/published-content.php +++ b/views/widgets/published-content.php @@ -40,7 +40,7 @@
- + @@ -53,10 +53,10 @@ diff --git a/views/widgets/published-pages.php b/views/widgets/published-pages.php index a6e6f15c1..b78581f62 100644 --- a/views/widgets/published-pages.php +++ b/views/widgets/published-pages.php @@ -35,7 +35,7 @@
- + @@ -48,10 +48,10 @@ publish ) + esc_html( number_format_i18n( $prpl_last_week_pages ) ), + esc_html( number_format_i18n( $prpl_all_pages_count->publish ) ) ); ?> diff --git a/views/widgets/published-posts.php b/views/widgets/published-posts.php index 784018472..a3a90f44c 100644 --- a/views/widgets/published-posts.php +++ b/views/widgets/published-posts.php @@ -35,7 +35,7 @@
- + @@ -48,10 +48,10 @@ publish ) + /* translators: %1$s: number of posts published this week. %2$s: Total number of posts. */ + esc_html__( 'Good job! You added %1$s posts in the past week. You now have %2$s posts in total.', 'progress-planner' ), + esc_html( number_format_i18n( $prpl_last_week_posts ) ), + esc_html( number_format_i18n( $prpl_all_posts_count->publish ) ) ); ?> diff --git a/views/widgets/published-words.php b/views/widgets/published-words.php index fad3f7476..6fb280573 100644 --- a/views/widgets/published-words.php +++ b/views/widgets/published-words.php @@ -70,7 +70,7 @@
- + @@ -83,10 +83,10 @@ From b6ce80ee27c93595da89b96789dcf845a8502012 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 8 Mar 2024 11:04:44 +0200 Subject: [PATCH 152/490] Add inline docs in the charts class --- includes/class-chart.php | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/includes/class-chart.php b/includes/class-chart.php index 75b32fe05..991314a84 100644 --- a/includes/class-chart.php +++ b/includes/class-chart.php @@ -35,6 +35,9 @@ class Chart { * @return void */ public function the_chart( $args = [] ) { + /* + * Set default values for the arguments. + */ $args = wp_parse_args( $args, [ @@ -76,12 +79,14 @@ public function the_chart( $args = [] ) { ] ); + // Get the periods for the chart. $periods = Date::get_periods( $args['dates_params']['start'], $args['dates_params']['end'], $args['dates_params']['frequency'] ); + // Prepare the data for the chart. $data = [ 'labels' => [], 'datasets' => [], @@ -96,13 +101,21 @@ public function the_chart( $args = [] ) { ], ]; - // Calculate zero stats to be used as the baseline. + /* + * Calculate zero stats to be used as the baseline. + * + * If this is an "additive" chart, + * we need to calculate the score for all activities before the first period. + */ $score = 0; if ( $args['additive'] ) { $oldest_activity = \progress_planner()->get_query()->get_oldest_activity(); if ( null !== $oldest_activity ) { + // Get the activities before the first period. + // We need to subtract one day from the start date to get the activities before the first period. $end_date = clone $args['dates_params']['start']; $end_date->modify( '-1 day' ); + // Get all activities before the first period. $activities = \progress_planner()->get_query()->query_activities( array_merge( $args['query_params'], @@ -112,13 +125,21 @@ public function the_chart( $args = [] ) { ] ) ); + // Filter the results if a callback is provided. if ( $args['filter_results'] ) { $activities = $args['filter_results']( $activities ); } + // Calculate the score for the activities. $score = $args['count_callback']( $activities ); } } + /* + * "Normalized" charts decay the score of previous months activities, + * and add them to the current month score. + * This means that for "normalized" charts, we need to get activities + * for the month prior to the first period. + */ $previous_month_activities = []; if ( $args['normalized'] ) { $previous_month_start = clone $periods[0]['start']; @@ -138,7 +159,9 @@ public function the_chart( $args = [] ) { } } + // Loop through the periods and calculate the score for each period. foreach ( $periods as $period ) { + // Get the activities for the period. $activities = \progress_planner()->get_query()->query_activities( array_merge( $args['query_params'], @@ -148,13 +171,18 @@ public function the_chart( $args = [] ) { ] ) ); + // Filter the results if a callback is provided. if ( $args['filter_results'] ) { $activities = $args['filter_results']( $activities ); } - $data['labels'][] = $period['dates'][0]->format( $args['dates_params']['format'] ); + // Add the label for the period. + $data['labels'][] = $period['start']->format( $args['dates_params']['format'] ); + // Calculate the score for the period. $period_score = $args['count_callback']( $activities, $period['start'] ); + + // If this is a "normalized" chart, we need to calculate the score for the previous month activities. if ( $args['normalized'] ) { // Add the previous month activities to the current month score. $period_score += $args['count_callback']( $previous_month_activities, $period['start'] ); @@ -162,11 +190,15 @@ public function the_chart( $args = [] ) { $previous_month_activities = $activities; } + // "Additive" charts add the score for the period to the previous score. $score = $args['additive'] ? $score + $period_score : $period_score; - $datasets[0]['data'][] = null === $args['max'] + // Apply a "max" limit to the score if max is defined in the arguments. + $datasets[0]['data'][] = null === $args['max'] ? $score : min( $score, $args['max'] ); + + // Calculate the colors for the score. $datasets[0]['backgroundColor'][] = $args['colors']['background']( $score ); $datasets[0]['borderColor'][] = $args['colors']['border']( $score ); } From 5f83d12578b8dddef62a1f937ecb7822f757f1e3 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 8 Mar 2024 11:05:04 +0200 Subject: [PATCH 153/490] Simplify date ranges --- includes/class-date.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/includes/class-date.php b/includes/class-date.php index 3d6fa1c17..a4ecae9b3 100644 --- a/includes/class-date.php +++ b/includes/class-date.php @@ -19,9 +19,8 @@ class Date { * @param string|int $end The end date. * * @return array [ - * 'start' => 'Ymd', - * 'end' => 'Ymd', - * 'dates' => [ 'Ymd', 'Ymd', ... ], + * 'start' => \DateTime, + * 'end' => \DateTime, * ]. */ public static function get_range( $start, $end ) { @@ -29,7 +28,6 @@ public static function get_range( $start, $end ) { return [ 'start' => $dates[0], 'end' => end( $dates ), - 'dates' => $dates, ]; } From 460396fc3b23ed647e16e5d02b9a032601087b7d Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 8 Mar 2024 11:49:53 +0200 Subject: [PATCH 154/490] Set min:0, max:100 in the axis for activity scores --- includes/class-chart.php | 2 ++ views/widgets/activity-scores.php | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/includes/class-chart.php b/includes/class-chart.php index 991314a84..26b6a3262 100644 --- a/includes/class-chart.php +++ b/includes/class-chart.php @@ -94,6 +94,8 @@ public function the_chart( $args = [] ) { $datasets = [ [ 'label' => '', + 'xAxisID' => 'xAxis', + 'yAxisID' => 'yAxis', 'data' => [], 'tension' => 0.2, 'backgroundColor' => [], diff --git a/views/widgets/activity-scores.php b/views/widgets/activity-scores.php index 8ae72bf48..3ff4eb9c5 100644 --- a/views/widgets/activity-scores.php +++ b/views/widgets/activity-scores.php @@ -45,7 +45,23 @@ 'format' => 'M', ], 'chart_params' => [ - 'type' => 'bar', + 'type' => 'bar', + 'options' => [ + 'responsive' => true, + 'maintainAspectRatio' => false, + 'pointStyle' => false, + 'plugins' => [ + 'legend' => [ + 'display' => false, + ], + ], + 'scales' => [ + 'yAxis' => [ + 'min' => 0, + 'max' => 100, + ], + ], + ], ], 'count_callback' => function ( $activities, $date ) { $score = 0; From 245bfa506511efaceebdf7e0b124302eb1d7994a Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 8 Mar 2024 11:50:10 +0200 Subject: [PATCH 155/490] multiply scores by 100 to get % --- views/widgets/activity-scores.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/widgets/activity-scores.php b/views/widgets/activity-scores.php index 3ff4eb9c5..bcbc416c5 100644 --- a/views/widgets/activity-scores.php +++ b/views/widgets/activity-scores.php @@ -69,7 +69,7 @@ $score += $activity->get_points( $date ); } $target = \progress_planner()->get_dev_config( 'activity-score-target' ); - return $score / $target; + return $score * 100 / $target; }, 'additive' => false, 'normalized' => true, From 60dba6dbe16ce763fc9e6c985b0c1f6dc05da61e Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 8 Mar 2024 11:59:38 +0200 Subject: [PATCH 156/490] Make the Y axis in graphs use integers --- includes/class-chart.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/includes/class-chart.php b/includes/class-chart.php index 26b6a3262..bd048a750 100644 --- a/includes/class-chart.php +++ b/includes/class-chart.php @@ -70,6 +70,13 @@ public function the_chart( $args = [] ) { 'responsive' => true, 'maintainAspectRatio' => false, 'pointStyle' => false, + 'scales' => [ + 'yAxis' => [ + 'ticks' => [ + 'precision' => 0, + ], + ], + ], 'plugins' => [ 'legend' => [ 'display' => false, From e4c517a0b50c2b0d04092d951ff9342d4abb9f6c Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 8 Mar 2024 12:27:29 +0200 Subject: [PATCH 157/490] Combine content widgets --- assets/css/admin.css | 23 +++++++++++ views/admin-page.php | 4 +- views/widgets/published-content.php | 64 ++++++++++++++++++----------- 3 files changed, 66 insertions(+), 25 deletions(-) diff --git a/assets/css/admin.css b/assets/css/admin.css index c3434d4ec..cb0521dc0 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -189,3 +189,26 @@ Set variables. .progress-wrapper .progress-label { display: inline-block; } + +.prpl-widget-wrapper.prpl-published-content table { + width: 100%; + margin-bottom: 1em; + padding: calc(var(--prpl-gap) / 2) 0; + /* border: 1px solid var(--prpl-color-gray-2); */ + /* border-radius: var(--prpl-border-radius); */ + border-top: 1px solid var(--prpl-color-gray-3); + border-bottom: 1px solid var(--prpl-color-gray-3); +} + +.prpl-widget-wrapper.prpl-published-content th { + text-align: start; +} + +.prpl-widget-wrapper.prpl-published-content td { + padding: 0.5em; + border-bottom: 1px solid var(--prpl-color-gray-1); +} + +.prpl-widget-wrapper.prpl-published-content tr:last-child td { + border-bottom: none; +} diff --git a/views/admin-page.php b/views/admin-page.php index a7aa793b3..22f2beddf 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -23,8 +23,8 @@ 'published-content', 'activity-scores', // 'latest-badge', - 'published-pages', - 'published-posts', + // 'published-pages', + // 'published-posts', 'published-content-density', 'published-words', 'badges-progress', diff --git a/views/widgets/published-content.php b/views/widgets/published-content.php index b1f85cf18..0507de3ed 100644 --- a/views/widgets/published-content.php +++ b/views/widgets/published-content.php @@ -14,33 +14,33 @@ // phpcs:ignore WordPress.Security.NonceVerification.Recommended $prpl_active_frequency = isset( $_GET['frequency'] ) ? sanitize_text_field( wp_unslash( $_GET['frequency'] ) ) : 'monthly'; -// Get the content published this week. -$prpl_last_week_content = count( - get_posts( - [ - 'post_status' => 'publish', - 'post_type' => Content_Helpers::get_post_types_names(), - 'date_query' => [ - [ - 'after' => '1 week ago', +$prpl_post_types = Content_Helpers::get_post_types_names(); +$prpl_last_week_content = []; +$prpl_all_content_count = []; +foreach ( $prpl_post_types as $prpl_post_type ) { + // Get the content published this week. + $prpl_last_week_content[ $prpl_post_type ] = count( + get_posts( + [ + 'post_status' => 'publish', + 'post_type' => $prpl_post_type, + 'date_query' => [ + [ + 'after' => '1 week ago', + ], ], - ], - 'posts_per_page' => 100, - ] - ) -); - -// Get the total number of posts for this week. -$prpl_all_content_count = 0; -foreach ( Content_Helpers::get_post_types_names() as $prpl_post_type ) { - $prpl_all_content_count += wp_count_posts( $prpl_post_type )->publish; + 'posts_per_page' => 100, + ] + ) + ); + // Get the total number of posts for this post-type. + $prpl_all_content_count[ $prpl_post_type ] = wp_count_posts( $prpl_post_type )->publish; } - ?>
- + @@ -55,12 +55,30 @@ printf( /* translators: %1$s: number of posts/pages published this week. %2$s: Total number of posts. */ esc_html__( 'Good job! You added %1$s pieces of content in the past week. You now have %2$s in total.', 'progress-planner' ), - esc_html( number_format_i18n( $prpl_last_week_content ) ), - esc_html( number_format_i18n( $prpl_all_content_count ) ) + esc_html( number_format_i18n( array_sum( $prpl_last_week_content ) ) ), + esc_html( number_format_i18n( array_sum( $prpl_all_content_count ) ) ) ); ?>

+ + + + + + + + + + + + + + + + + +
From 52e545e30871ae87b50f5bd314e4923e6bc8f1d6 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 8 Mar 2024 12:32:55 +0200 Subject: [PATCH 158/490] Use the post-type label --- views/widgets/published-content.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/widgets/published-content.php b/views/widgets/published-content.php index 0507de3ed..58f5ff8f3 100644 --- a/views/widgets/published-content.php +++ b/views/widgets/published-content.php @@ -72,7 +72,7 @@ - + labels->name ); ?> From 605e8369abc565fef04f278102f8a1594a4f7a36 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 8 Mar 2024 13:57:56 +0200 Subject: [PATCH 159/490] tweak the published-content widget --- views/admin-page.php | 2 +- views/widgets/published-content.php | 124 ++++++++++++++-------------- 2 files changed, 64 insertions(+), 62 deletions(-) diff --git a/views/admin-page.php b/views/admin-page.php index 22f2beddf..c0874d5aa 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -20,12 +20,12 @@ publish; } ?> -
-
- - - - - - -
-
-

- - - - - -

- - - - - - - - - - +
+
+
+ + + + + + +
+
+

+ + + + + +

+
+ - - - + + + - - -
labels->name ); ?>
+ + + + + labels->name ); ?> + + + + + + +
-
-
- the_chart( - [ - 'query_params' => [ - 'category' => 'content', - 'type' => 'publish', - ], - 'dates_params' => [ - 'start' => \DateTime::createFromFormat( 'Y-m-d', \gmdate( 'Y-m-01' ) )->modify( $prpl_active_range ), - 'end' => new \DateTime(), - 'frequency' => $prpl_active_frequency, - 'format' => 'M, d', - ], - 'chart_params' => [ - 'type' => 'line', +
+ the_chart( + [ + 'query_params' => [ + 'category' => 'content', + 'type' => 'publish', + ], + 'dates_params' => [ + 'start' => \DateTime::createFromFormat( 'Y-m-d', \gmdate( 'Y-m-01' ) )->modify( $prpl_active_range ), + 'end' => new \DateTime(), + 'frequency' => $prpl_active_frequency, + 'format' => 'M', + ], + 'chart_params' => [ + 'type' => 'line', + ], + 'additive' => false, ], - 'additive' => false, - ], - ); - ?> + ); + ?> +
From eebd06c3c0f6987a24545a35a99d23f35dc6406d Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 8 Mar 2024 13:59:26 +0200 Subject: [PATCH 160/490] Tweak date queries --- includes/class-query.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/class-query.php b/includes/class-query.php index f78da9ab3..93fc1a3dc 100644 --- a/includes/class-query.php +++ b/includes/class-query.php @@ -124,13 +124,13 @@ public function query_activities( $args, $return_type = 'ACTIVITIES' ) { if ( $args['start_date'] !== null ) { $where_args[] = 'date >= %s'; $prepare_args[] = ( $args['start_date'] instanceof \Datetime ) - ? $args['start_date']->format( 'Y-m-d H:i:s' ) + ? $args['start_date']->format( 'Y-m-d' ) : $args['start_date']; } if ( $args['end_date'] !== null ) { $where_args[] = 'date <= %s'; $prepare_args[] = ( $args['end_date'] instanceof \Datetime ) - ? $args['end_date']->format( 'Y-m-d H:i:s' ) + ? $args['end_date']->format( 'Y-m-d' ) : $args['end_date']; } if ( $args['category'] !== null ) { From 7c57ce7e293c6b03632df4fa6b2b1e5d4f3eb2a5 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 8 Mar 2024 13:59:49 +0200 Subject: [PATCH 161/490] Make published-content widget additive --- views/widgets/published-content.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/widgets/published-content.php b/views/widgets/published-content.php index 1f9a7bbc5..27ae2d0bc 100644 --- a/views/widgets/published-content.php +++ b/views/widgets/published-content.php @@ -99,7 +99,7 @@ 'chart_params' => [ 'type' => 'line', ], - 'additive' => false, + 'additive' => true, ], ); ?> From 4c5de3a1d2732234026878a4a9a68c052852344f Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 8 Mar 2024 14:00:12 +0200 Subject: [PATCH 162/490] Minor tweak in charts class --- includes/class-chart.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/includes/class-chart.php b/includes/class-chart.php index bd048a750..7242d4190 100644 --- a/includes/class-chart.php +++ b/includes/class-chart.php @@ -122,15 +122,13 @@ public function the_chart( $args = [] ) { if ( null !== $oldest_activity ) { // Get the activities before the first period. // We need to subtract one day from the start date to get the activities before the first period. - $end_date = clone $args['dates_params']['start']; - $end_date->modify( '-1 day' ); // Get all activities before the first period. $activities = \progress_planner()->get_query()->query_activities( array_merge( $args['query_params'], [ 'start_date' => $oldest_activity->get_date(), - 'end_date' => $end_date, + 'end_date' => ( clone $periods[0]['start'] )->modify( '-1 day' ), ] ) ); From b3c5825ec93f60261a169233c036f11855c138af Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 8 Mar 2024 14:31:48 +0200 Subject: [PATCH 163/490] Add badges --- assets/css/admin.css | 12 +++-- assets/images/badges/streak_badge1.svg | 1 + assets/images/badges/streak_badge1_gray.svg | 1 + assets/images/badges/streak_badge2.svg | 1 + assets/images/badges/streak_badge2_gray.svg | 1 + assets/images/badges/streak_badge3.svg | 1 + assets/images/badges/streak_badge3_gray.svg | 1 + assets/images/badges/writing_badge1.svg | 1 + assets/images/badges/writing_badge1_gray.svg | 1 + assets/images/badges/writing_badge2.svg | 1 + assets/images/badges/writing_badge2_gray.svg | 1 + assets/images/badges/writing_badge3.svg | 1 + assets/images/badges/writing_badge3_gray.svg | 1 + includes/class-badges.php | 56 +++++++++++++------- views/widgets/badges-progress.php | 36 ++++++++----- 15 files changed, 82 insertions(+), 34 deletions(-) create mode 100644 assets/images/badges/streak_badge1.svg create mode 100644 assets/images/badges/streak_badge1_gray.svg create mode 100644 assets/images/badges/streak_badge2.svg create mode 100644 assets/images/badges/streak_badge2_gray.svg create mode 100644 assets/images/badges/streak_badge3.svg create mode 100644 assets/images/badges/streak_badge3_gray.svg create mode 100644 assets/images/badges/writing_badge1.svg create mode 100644 assets/images/badges/writing_badge1_gray.svg create mode 100644 assets/images/badges/writing_badge2.svg create mode 100644 assets/images/badges/writing_badge2_gray.svg create mode 100644 assets/images/badges/writing_badge3.svg create mode 100644 assets/images/badges/writing_badge3_gray.svg diff --git a/assets/css/admin.css b/assets/css/admin.css index cb0521dc0..c387a55fe 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -173,23 +173,29 @@ Set variables. margin-top: -1em; } -.progress-wrapper .progress-bar { +.prpl-widget-wrapper.prpl-badges-progress .progress-bar { height: 1em; background-color: var(--prpl-color-gray-1); width: 100%; display: inline-block; } -.progress-wrapper .progress-bar > span { +.prpl-widget-wrapper.prpl-badges-progress .progress-bar > span { background-color: var(--color); height: 1em; display: block; } -.progress-wrapper .progress-label { +.prpl-widget-wrapper.prpl-badges-progress .progress-label { display: inline-block; } +.prpl-widget-wrapper.prpl-badges-progress .progress-wrapper { + display: grid; + grid-template-columns: 1fr 1fr 1fr; + grid-gap: var(--prpl-gap); +} + .prpl-widget-wrapper.prpl-published-content table { width: 100%; margin-bottom: 1em; diff --git a/assets/images/badges/streak_badge1.svg b/assets/images/badges/streak_badge1.svg new file mode 100644 index 000000000..768a3538f --- /dev/null +++ b/assets/images/badges/streak_badge1.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/images/badges/streak_badge1_gray.svg b/assets/images/badges/streak_badge1_gray.svg new file mode 100644 index 000000000..fa71456e6 --- /dev/null +++ b/assets/images/badges/streak_badge1_gray.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/images/badges/streak_badge2.svg b/assets/images/badges/streak_badge2.svg new file mode 100644 index 000000000..155aeae9c --- /dev/null +++ b/assets/images/badges/streak_badge2.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/images/badges/streak_badge2_gray.svg b/assets/images/badges/streak_badge2_gray.svg new file mode 100644 index 000000000..4888d261b --- /dev/null +++ b/assets/images/badges/streak_badge2_gray.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/images/badges/streak_badge3.svg b/assets/images/badges/streak_badge3.svg new file mode 100644 index 000000000..9b6bf3605 --- /dev/null +++ b/assets/images/badges/streak_badge3.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/images/badges/streak_badge3_gray.svg b/assets/images/badges/streak_badge3_gray.svg new file mode 100644 index 000000000..c62be9873 --- /dev/null +++ b/assets/images/badges/streak_badge3_gray.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/images/badges/writing_badge1.svg b/assets/images/badges/writing_badge1.svg new file mode 100644 index 000000000..65e1175e1 --- /dev/null +++ b/assets/images/badges/writing_badge1.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/images/badges/writing_badge1_gray.svg b/assets/images/badges/writing_badge1_gray.svg new file mode 100644 index 000000000..f99f6cef1 --- /dev/null +++ b/assets/images/badges/writing_badge1_gray.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/images/badges/writing_badge2.svg b/assets/images/badges/writing_badge2.svg new file mode 100644 index 000000000..cc07fd3a7 --- /dev/null +++ b/assets/images/badges/writing_badge2.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/images/badges/writing_badge2_gray.svg b/assets/images/badges/writing_badge2_gray.svg new file mode 100644 index 000000000..10c93525e --- /dev/null +++ b/assets/images/badges/writing_badge2_gray.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/images/badges/writing_badge3.svg b/assets/images/badges/writing_badge3.svg new file mode 100644 index 000000000..031523c12 --- /dev/null +++ b/assets/images/badges/writing_badge3.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/images/badges/writing_badge3_gray.svg b/assets/images/badges/writing_badge3_gray.svg new file mode 100644 index 000000000..3b1a81816 --- /dev/null +++ b/assets/images/badges/writing_badge3_gray.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/includes/class-badges.php b/includes/class-badges.php index dfdaa8dda..b489a0f8e 100644 --- a/includes/class-badges.php +++ b/includes/class-badges.php @@ -96,7 +96,7 @@ public function get_badge_progress( $badge_id ) { foreach ( $badge['steps'] as $step ) { $progress[] = [ 'name' => $step['name'], - 'icon' => $step['icon'], + 'icons' => $step['icons-svg'], 'progress' => $badge['progress_callback']( $step['target'] ), ]; } @@ -116,19 +116,28 @@ private function register_badges() { [ 'steps' => [ [ - 'target' => 'wonderful-writer', - 'name' => __( 'Wonderful Writer', 'progress-planner' ), - 'icon' => '🏆', + 'target' => 'wonderful-writer', + 'name' => __( 'Wonderful Writer', 'progress-planner' ), + 'icons-svg' => [ + \PROGRESS_PLANNER_DIR . '/assets/images/badges/writing_badge1_gray.svg', + \PROGRESS_PLANNER_DIR . '/assets/images/badges/writing_badge1.svg', + ], ], [ - 'target' => 'awesome-author', - 'name' => __( 'Awesome Author', 'progress-planner' ), - 'icon' => '🏆', + 'target' => 'awesome-author', + 'name' => __( 'Awesome Author', 'progress-planner' ), + 'icons-svg' => [ + \PROGRESS_PLANNER_DIR . '/assets/images/badges/writing_badge2_gray.svg', + \PROGRESS_PLANNER_DIR . '/assets/images/badges/writing_badge2.svg', + ], ], [ - 'target' => 'notorious-novelist', - 'name' => __( 'Notorious Novelist', 'progress-planner' ), - 'icon' => '🏆', + 'target' => 'notorious-novelist', + 'name' => __( 'Notorious Novelist', 'progress-planner' ), + 'icons-svg' => [ + \PROGRESS_PLANNER_DIR . '/assets/images/badges/writing_badge3_gray.svg', + \PROGRESS_PLANNER_DIR . '/assets/images/badges/writing_badge3.svg', + ], ], ], 'progress_callback' => function ( $target ) { @@ -201,19 +210,28 @@ private function register_badges() { [ 'steps' => [ [ - 'target' => 6, - 'name' => __( 'Progress Professional', 'progress-planner' ), - 'icon' => '🏆', + 'target' => 6, + 'name' => __( 'Progress Professional', 'progress-planner' ), + 'icons-svg' => [ + \PROGRESS_PLANNER_DIR . '/assets/images/badges/streak_badge1_gray.svg', + \PROGRESS_PLANNER_DIR . '/assets/images/badges/streak_badge1.svg', + ], ], [ - 'target' => 26, - 'name' => __( 'Maintenance Maniac', 'progress-planner' ), - 'icon' => '🏆', + 'target' => 26, + 'name' => __( 'Maintenance Maniac', 'progress-planner' ), + 'icons-svg' => [ + \PROGRESS_PLANNER_DIR . '/assets/images/badges/streak_badge2_gray.svg', + \PROGRESS_PLANNER_DIR . '/assets/images/badges/streak_badge2.svg', + ], ], [ - 'target' => 52, - 'name' => __( 'Super Site Specialist', 'progress-planner' ), - 'icon' => '🏆', + 'target' => 52, + 'name' => __( 'Super Site Specialist', 'progress-planner' ), + 'icons-svg' => [ + \PROGRESS_PLANNER_DIR . '/assets/images/badges/streak_badge3_gray.svg', + \PROGRESS_PLANNER_DIR . '/assets/images/badges/streak_badge3.svg', + ], ], ], 'progress_callback' => function ( $target ) { diff --git a/views/widgets/badges-progress.php b/views/widgets/badges-progress.php index 9d5e05c48..f1db36eba 100644 --- a/views/widgets/badges-progress.php +++ b/views/widgets/badges-progress.php @@ -38,19 +38,31 @@ get_badges()->get_badge_progress( $prpl_badge['id'] ); ?> $prpl_badge_step_progress ) : ?> -

- - -

+ +

+ +

+ +
+ +
+
+ % +
+
-

-
- -
-
- % -
- + +

+ +

+ +
+ +
+
+ % +
+

From 2da6abcaec8b3dedf31f4acd7e723a2ea924b57b Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 11 Mar 2024 08:51:43 +0200 Subject: [PATCH 164/490] Add plugins widget --- views/admin-page.php | 1 + views/widgets/plugins.php | 41 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 views/widgets/plugins.php diff --git a/views/admin-page.php b/views/admin-page.php index c0874d5aa..542628874 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -28,6 +28,7 @@ 'published-content', 'published-words', 'badges-progress', + 'plugins', '__filter-numbers', ] as $prpl_widget ) { echo '
'; diff --git a/views/widgets/plugins.php b/views/widgets/plugins.php new file mode 100644 index 000000000..6d0f7e6e6 --- /dev/null +++ b/views/widgets/plugins.php @@ -0,0 +1,41 @@ + + +
+
+ + + + + + +
+
+

+ + + + + +

+
+
From 8b94a09eedaa8decde5ca662dded8d7535029304 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 11 Mar 2024 08:56:09 +0200 Subject: [PATCH 165/490] simplify badges widget --- views/widgets/badges-progress.php | 40 ++++++++++--------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/views/widgets/badges-progress.php b/views/widgets/badges-progress.php index f1db36eba..431f50309 100644 --- a/views/widgets/badges-progress.php +++ b/views/widgets/badges-progress.php @@ -37,33 +37,19 @@
get_badges()->get_badge_progress( $prpl_badge['id'] ); ?> $prpl_badge_step_progress ) : ?> - - -

- -

- -
- -
-
- % -
-
- - -

- -

- -
- -
-
- % -
-
- + + +

+ +

+ +
+ +
+
+ % +
+

From c90a97b780d940e9c60f0438e079913e059eff51 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 11 Mar 2024 09:58:25 +0200 Subject: [PATCH 166/490] Add badge-content widget and tweak the badges-progress widget --- assets/css/admin.css | 45 +++++++++++++++------- views/admin-page.php | 1 + views/widgets/badge-content.php | 62 +++++++++++++++++++++++++++++++ views/widgets/badges-progress.php | 17 +++++---- 4 files changed, 104 insertions(+), 21 deletions(-) create mode 100644 views/widgets/badge-content.php diff --git a/assets/css/admin.css b/assets/css/admin.css index c387a55fe..df607b201 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -173,19 +173,6 @@ Set variables. margin-top: -1em; } -.prpl-widget-wrapper.prpl-badges-progress .progress-bar { - height: 1em; - background-color: var(--prpl-color-gray-1); - width: 100%; - display: inline-block; -} - -.prpl-widget-wrapper.prpl-badges-progress .progress-bar > span { - background-color: var(--color); - height: 1em; - display: block; -} - .prpl-widget-wrapper.prpl-badges-progress .progress-label { display: inline-block; } @@ -218,3 +205,35 @@ Set variables. .prpl-widget-wrapper.prpl-published-content tr:last-child td { border-bottom: none; } + +.prpl-badges-columns-wrapper { + display: grid; + grid-template-columns: 1fr 1fr; + grid-gap: var(--prpl-gap); +} + +.prpl-badge-gauge { + --cutout: 50%; + width: 100%; + aspect-ratio: 1 / 1; + border-radius: 100%; + background: + radial-gradient( var(--prpl-background-blue) 0 var(--cutout), transparent var(--cutout) 100% ), + conic-gradient( + from -135deg, + var(--color) calc( 270deg * var(--value) ), + var(--prpl-color-gray-1) calc( 270deg * var(--value) ) 270deg, + transparent 270deg + ); + text-align: center; +} + +.prpl-badge-gauge svg { + aspect-ratio: 1.15; +} + +.prpl-badge-wrapper { + background: var(--prpl-background-blue); + padding: var(--prpl-gap); + border-radius: var(--prpl-border-radius); +} diff --git a/views/admin-page.php b/views/admin-page.php index 542628874..5ccee2bc7 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -28,6 +28,7 @@ 'published-content', 'published-words', 'badges-progress', + 'badge-content', 'plugins', '__filter-numbers', ] as $prpl_widget ) { diff --git a/views/widgets/badge-content.php b/views/widgets/badge-content.php new file mode 100644 index 000000000..f58821526 --- /dev/null +++ b/views/widgets/badge-content.php @@ -0,0 +1,62 @@ +get_badges()->get_badge_progress( 'content_writing' ); + +// Get the badge to display. +foreach ( $prpl_badges as $prpl_badge_step ) { + $prpl_badge = $prpl_badge_step; + if ( 100 > $prpl_badge_step['progress'] ) { + $prpl_badge = $prpl_badge_step; + break; + } +} +// var_dump($prpl_badge); +/** + * Callback to get the progress color. + * + * @param int $progress The progress. + * + * @return string The color. + */ +$prpl_get_progress_color = function ( $progress ) { + $color = 'var(--prpl-color-accent-red)'; + if ( $progress > 50 ) { + $color = 'var(--prpl-color-accent-orange)'; + } + if ( $progress > 75 ) { + $color = 'var(--prpl-color-accent-green)'; + } + return $color; +}; + +?> +
+
+ +
+ +
+
+
+
+

+ +

+
+
diff --git a/views/widgets/badges-progress.php b/views/widgets/badges-progress.php index 431f50309..948d95d5e 100644 --- a/views/widgets/badges-progress.php +++ b/views/widgets/badges-progress.php @@ -38,17 +38,18 @@ get_badges()->get_badge_progress( $prpl_badge['id'] ); ?> $prpl_badge_step_progress ) : ?> - +

- -
- -
-
- % -
+

From d07424133bb84c98b38bf96ac778eeb56bd1c58a Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 11 Mar 2024 10:05:48 +0200 Subject: [PATCH 167/490] Add badge-streak widget and bugfix for the content widget --- views/admin-page.php | 1 + views/widgets/badge-content.php | 10 +++--- views/widgets/badge-streak.php | 62 +++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 views/widgets/badge-streak.php diff --git a/views/admin-page.php b/views/admin-page.php index 5ccee2bc7..33c7dab93 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -29,6 +29,7 @@ 'published-words', 'badges-progress', 'badge-content', + 'badge-streak', 'plugins', '__filter-numbers', ] as $prpl_widget ) { diff --git a/views/widgets/badge-content.php b/views/widgets/badge-content.php index f58821526..83489006d 100644 --- a/views/widgets/badge-content.php +++ b/views/widgets/badge-content.php @@ -18,7 +18,7 @@ break; } } -// var_dump($prpl_badge); + /** * Callback to get the progress color. * @@ -42,15 +42,15 @@
- +
diff --git a/views/widgets/badge-streak.php b/views/widgets/badge-streak.php new file mode 100644 index 000000000..274177521 --- /dev/null +++ b/views/widgets/badge-streak.php @@ -0,0 +1,62 @@ +get_badges()->get_badge_progress( 'streak_any_task' ); + +// Get the badge to display. +foreach ( $prpl_badges as $prpl_badge_step ) { + $prpl_badge = $prpl_badge_step; + if ( 100 > $prpl_badge_step['progress'] ) { + $prpl_badge = $prpl_badge_step; + break; + } +} + +/** + * Callback to get the progress color. + * + * @param int $progress The progress. + * + * @return string The color. + */ +$prpl_get_progress_color = function ( $progress ) { + $color = 'var(--prpl-color-accent-red)'; + if ( $progress > 50 ) { + $color = 'var(--prpl-color-accent-orange)'; + } + if ( $progress > 75 ) { + $color = 'var(--prpl-color-accent-green)'; + } + return $color; +}; + +?> +
+
+ +
+ +
+
+
+
+

+ +

+
+
From ba0a16d67f8b218feb0c009b401dce08d61a809e Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 11 Mar 2024 10:57:33 +0200 Subject: [PATCH 168/490] Admin page layout tweaks --- assets/css/admin.css | 41 +++++++++++++++++++------------ views/admin-page.php | 58 +++++++++++++++++++++++++++++--------------- 2 files changed, 65 insertions(+), 34 deletions(-) diff --git a/assets/css/admin.css b/assets/css/admin.css index df607b201..67b93495f 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -3,7 +3,7 @@ Set variables. */ .prpl-wrap { --prpl-gap: 20px; - --prpl-column-min-width: 22rem; + --prpl-column-min-width: 20rem; --prpl-max-columns: 4; --prpl-border-radius: 7px; @@ -49,7 +49,7 @@ Set variables. border: 1px solid var(--prpl-color-gray-3); border-radius: var(--prpl-border-radius); padding: var(--prpl-gap); - max-width: var(--prpl-container-max-width); + /* max-width: var(--prpl-container-max-width); */ color: var(--prpl-color-text); font-size: var(--prpl-font-size-base); line-height: 1.4 @@ -84,6 +84,24 @@ Set variables. grid-gap: var(--prpl-gap); } +.prpl-column-main { + display: grid; + grid-template-columns: repeat(auto-fit, minmax(var(--prpl-column-min-width), 1fr)); + grid-gap: var(--prpl-gap); +} + +.prpl-column { + display: flex; + flex-direction: column; + gap: var(--prpl-gap); +} + +.two-col { + display: grid; + grid-template-columns: repeat(auto-fit, minmax(var(--prpl-column-min-width), 1fr)); + grid-gap: var(--prpl-gap); +} + .prpl-widget-wrapper { border: 1px solid var(--prpl-color-gray-2); border-radius: var(--prpl-border-radius); @@ -116,26 +134,13 @@ Set variables. height: 100%; } -.prpl-widget-wrapper:has( > .two-col) { - grid-column: span 2; -} - -.prpl-widget-wrapper:has( > .two-col) .two-col { - display: grid; - grid-template-columns: 1fr 1fr; - height: 100%; - grid-gap: var(--prpl-gap); -} - .prpl-top-counter-bottom-content { display: flex; flex-direction: column; justify-content: space-between; - height: 100%; } .prpl-top-counter-bottom-content .counter-big-wrapper { - height: 100%; display: flex; flex-direction: column; justify-content: center; @@ -237,3 +242,9 @@ Set variables. padding: var(--prpl-gap); border-radius: var(--prpl-border-radius); } + +.prpl-chart-container { + position: relative; + height: 100%; + max-height: 500px; +} diff --git a/views/admin-page.php b/views/admin-page.php index 33c7dab93..989271bf7 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -12,32 +12,52 @@

- - - - -
- '; - include "widgets/{$prpl_widget}.php"; - echo '
'; - } - ?> + ], + ], + ]; + ?> + + + + + +
+ +
+ +
+ +
+ +
+ +
+ +
+

From 8a3029003f9d2298a22fef738d243e2f9ed5687a Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 11 Mar 2024 11:06:01 +0200 Subject: [PATCH 169/490] Add % progress in badges --- assets/css/admin.css | 8 ++++++++ views/widgets/badge-content.php | 1 + views/widgets/badge-streak.php | 1 + 3 files changed, 10 insertions(+) diff --git a/assets/css/admin.css b/assets/css/admin.css index 67b93495f..17d78400e 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -172,6 +172,14 @@ Set variables. align-items: center; } +.progress-percent { + font-size: var(--prpl-font-size-3xl); + line-height: 1; + font-weight: 600; + display: block; + text-align: center; +} + .prpl-gauge-number { font-size: var(--prpl-font-size-4xl); line-height: 1; diff --git a/views/widgets/badge-content.php b/views/widgets/badge-content.php index 83489006d..27da5e330 100644 --- a/views/widgets/badge-content.php +++ b/views/widgets/badge-content.php @@ -53,6 +53,7 @@ class="prpl-badge-gauge"
+ %

diff --git a/views/widgets/badge-streak.php b/views/widgets/badge-streak.php index 274177521..8d098793f 100644 --- a/views/widgets/badge-streak.php +++ b/views/widgets/badge-streak.php @@ -53,6 +53,7 @@ class="prpl-badge-gauge"

+ %

From 434fab03b27990aece3e911e0e54d87bc4b02025 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 11 Mar 2024 11:08:28 +0200 Subject: [PATCH 170/490] content-density is a 2-col widget --- views/widgets/published-content-density.php | 86 +++++++++++---------- 1 file changed, 44 insertions(+), 42 deletions(-) diff --git a/views/widgets/published-content-density.php b/views/widgets/published-content-density.php index 17ab5ea25..eace88f63 100644 --- a/views/widgets/published-content-density.php +++ b/views/widgets/published-content-density.php @@ -72,48 +72,50 @@ ); ?> -
-
- - - - - - +
+
+
+ + + + + + +
+
+

+ +

+
-
-

- -

-
-
-
- the_chart( - [ - 'query_params' => [ - 'category' => 'content', - 'type' => 'publish', - ], - 'dates_params' => [ - 'start' => \DateTime::createFromFormat( 'Y-m-d', \gmdate( 'Y-m-01' ) )->modify( $prpl_active_range ), - 'end' => new \DateTime(), - 'frequency' => $prpl_active_frequency, - 'format' => 'M', - ], - 'chart_params' => [ - 'type' => 'line', +
+ the_chart( + [ + 'query_params' => [ + 'category' => 'content', + 'type' => 'publish', + ], + 'dates_params' => [ + 'start' => \DateTime::createFromFormat( 'Y-m-d', \gmdate( 'Y-m-01' ) )->modify( $prpl_active_range ), + 'end' => new \DateTime(), + 'frequency' => $prpl_active_frequency, + 'format' => 'M', + ], + 'chart_params' => [ + 'type' => 'line', + ], + 'count_callback' => $prpl_count_density_callback, + 'additive' => false, ], - 'count_callback' => $prpl_count_density_callback, - 'additive' => false, - ], - ); - ?> + ); + ?> +
From 9ac16988aed8474472d14d01693b51b7574e25d3 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 11 Mar 2024 11:27:13 +0200 Subject: [PATCH 171/490] Remove all-time words count --- views/widgets/published-words.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/views/widgets/published-words.php b/views/widgets/published-words.php index 6fb280573..931a836df 100644 --- a/views/widgets/published-words.php +++ b/views/widgets/published-words.php @@ -38,11 +38,6 @@ return $words; }; -// Get the all-time words count. -$prpl_all_time_words = $prpl_count_words_callback( - \progress_planner()->get_query()->query_activities( $prpl_query_args ) -); - // Get the weekly words count. $prpl_this_week_words = $prpl_count_words_callback( \progress_planner()->get_query()->query_activities( @@ -84,9 +79,8 @@ From d50581db2271d8d0cd8d59a7f0528d797dd3e8d5 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 11 Mar 2024 11:41:47 +0200 Subject: [PATCH 172/490] Styling tweaks --- assets/css/admin.css | 21 +++++++++++++++++++++ views/widgets/badges-progress.php | 5 +---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/assets/css/admin.css b/assets/css/admin.css index 17d78400e..4b54743ce 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -256,3 +256,24 @@ Set variables. height: 100%; max-height: 500px; } + +.prpl-widget-wrapper.prpl-badge-streak .prpl-badge-wrapper { + background-color: var(--prpl-background-red); +} + +.prpl-widget-wrapper.prpl-badges-progress .progress-wrapper { + background-color: var(--prpl-background-blue); + padding: calc(var(--prpl-gap) / 2); + border-radius: var(--prpl-border-radius); + margin-bottom: var(--prpl-gap); +} + +.prpl-widget-wrapper.prpl-badges-progress .progress-wrapper p { + margin: 0; + font-size:var(--prpl-font-size-small); + text-align:center; +} + +.prpl-widget-wrapper.prpl-badges-progress .progress-wrapper + .progress-wrapper { + background-color: var(--prpl-background-red); +} diff --git a/views/widgets/badges-progress.php b/views/widgets/badges-progress.php index 948d95d5e..e56b13037 100644 --- a/views/widgets/badges-progress.php +++ b/views/widgets/badges-progress.php @@ -42,16 +42,13 @@ class="prpl-badge" data-value="" > -

- -

+

-
From b14a854ac7927266cd0453661dbe4bb08322ab9d Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 11 Mar 2024 11:51:34 +0200 Subject: [PATCH 173/490] Floor the activity score --- views/widgets/website-activity-score.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/views/widgets/website-activity-score.php b/views/widgets/website-activity-score.php index d8d248d48..cfa0613ad 100644 --- a/views/widgets/website-activity-score.php +++ b/views/widgets/website-activity-score.php @@ -39,6 +39,8 @@ $prpl_gauge_color = 'var(--prpl-color-accent-green)'; } +$prpl_score = floor( $prpl_score ); + ?>

From ba0861206ede97659e61d5f643e7575a4dd37234 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 11 Mar 2024 12:25:31 +0200 Subject: [PATCH 174/490] more styling tweaks --- assets/css/admin.css | 65 +++++++++++------------- views/widgets/website-activity-score.php | 13 +++-- 2 files changed, 41 insertions(+), 37 deletions(-) diff --git a/assets/css/admin.css b/assets/css/admin.css index 4b54743ce..eea5d5445 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -146,32 +146,6 @@ Set variables. justify-content: center; } -.prpl-gauge-container { - padding: var(--prpl-gap); - background-color: var(--prpl-background-orange); - border-radius: var(--prpl-border-radius); - height: 50%; - overflow: hidden; -} - -.prpl-gauge { - --deg: calc(var(--percent) * 1.8deg); /* 100% = 180deg */ - --thickness: 2rem; - width: 100%; - aspect-ratio: 1; - background-image: - radial-gradient(closest-side, var(--prpl-background-orange) 0%, var(--prpl-background-orange) calc(100% - var(--thickness)), transparent calc(100% - var(--thickness))), - conic-gradient(from -90deg, var(--accent) 0deg var(--deg), transparent var(--deg) 180deg), - conic-gradient(from -90deg, var(--prpl-color-gray-1) 0deg 180deg, transparent 180deg); - border-radius: 50%; - display: flex; - justify-content: center; - box-sizing: border-box; - margin: 0; - padding: 0; - align-items: center; -} - .progress-percent { font-size: var(--prpl-font-size-3xl); line-height: 1; @@ -225,22 +199,45 @@ Set variables. grid-gap: var(--prpl-gap); } -.prpl-badge-gauge { +.prpl-badge-gauge, +.prpl-activities-gauge { + --background: var(--prpl-background-blue); --cutout: 50%; + --max: 270deg; + --start: -135deg; width: 100%; aspect-ratio: 1 / 1; border-radius: 100%; + position: relative; background: - radial-gradient( var(--prpl-background-blue) 0 var(--cutout), transparent var(--cutout) 100% ), + radial-gradient( var(--background) 0 var(--cutout), transparent var(--cutout) 100% ), conic-gradient( - from -135deg, - var(--color) calc( 270deg * var(--value) ), - var(--prpl-color-gray-1) calc( 270deg * var(--value) ) 270deg, - transparent 270deg + from var(--start), + var(--color) calc( var(--max) * var(--value) ), + var(--prpl-color-gray-1) calc( var(--max) * var(--value) ) var(--max), + transparent var(--max) ); text-align: center; } +.prpl-activities-gauge-container { + padding: var(--prpl-gap); + background: var(--prpl-background-orange); + border-radius: var(--prpl-border-radius); + aspect-ratio: 1 / 1; + top: 50%; +} + +.prpl-activities-gauge-container .prpl-gauge-number { + display: block; + padding-top: 50%; + font-weight: 700; + text-align: center; + position: absolute; + width: 100%; + line-height: 2; +} + .prpl-badge-gauge svg { aspect-ratio: 1.15; } @@ -258,7 +255,7 @@ Set variables. } .prpl-widget-wrapper.prpl-badge-streak .prpl-badge-wrapper { - background-color: var(--prpl-background-red); + background-color: var(--prpl-background-orange); } .prpl-widget-wrapper.prpl-badges-progress .progress-wrapper { @@ -275,5 +272,5 @@ Set variables. } .prpl-widget-wrapper.prpl-badges-progress .progress-wrapper + .progress-wrapper { - background-color: var(--prpl-background-red); + background-color: var(--prpl-background-orange); } diff --git a/views/widgets/website-activity-score.php b/views/widgets/website-activity-score.php index cfa0613ad..6286542ec 100644 --- a/views/widgets/website-activity-score.php +++ b/views/widgets/website-activity-score.php @@ -47,14 +47,21 @@

-
-
+
+
-

Bla bla bla

Bla bla bli

From 93247a0f533c622bae9e297654e6158116a3a1f9 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 11 Mar 2024 12:28:25 +0200 Subject: [PATCH 175/490] tweak for badges stats display --- views/widgets/badge-content.php | 2 ++ views/widgets/badge-streak.php | 2 ++ 2 files changed, 4 insertions(+) diff --git a/views/widgets/badge-content.php b/views/widgets/badge-content.php index 27da5e330..acd8176e1 100644 --- a/views/widgets/badge-content.php +++ b/views/widgets/badge-content.php @@ -48,6 +48,8 @@ class="prpl-badge" class="prpl-badge-gauge" style=" --value:; + --max: 360deg; + --start: 180deg; --color: "> diff --git a/views/widgets/badge-streak.php b/views/widgets/badge-streak.php index 8d098793f..b787d0170 100644 --- a/views/widgets/badge-streak.php +++ b/views/widgets/badge-streak.php @@ -48,6 +48,8 @@ class="prpl-badge" class="prpl-badge-gauge" style=" --value:; + --max: 360deg; + --start: 180deg; --color: "> From 2c9561dae446545d67d9aee07c7bc30793de7432 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 11 Mar 2024 13:11:14 +0200 Subject: [PATCH 176/490] Add personal-record widget & fix CS issues --- includes/class-badges.php | 45 +++++++++++++++++++++++ views/admin-page.php | 1 + views/widgets/activity-scores.php | 2 +- views/widgets/badge-content.php | 2 +- views/widgets/badge-streak.php | 2 +- views/widgets/badges-progress.php | 5 +++ views/widgets/personal-record-content.php | 11 ++++++ 7 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 views/widgets/personal-record-content.php diff --git a/includes/class-badges.php b/includes/class-badges.php index b489a0f8e..1299d018c 100644 --- a/includes/class-badges.php +++ b/includes/class-badges.php @@ -93,6 +93,10 @@ public function get_badge_progress( $badge_id ) { $progress = []; + if ( ! isset( $badge['steps'] ) ) { + return $badge['progress_callback'](); + } + foreach ( $badge['steps'] as $step ) { $progress[] = [ 'name' => $step['name'], @@ -114,6 +118,7 @@ private function register_badges() { $this->register_badge( 'content_writing', [ + 'public' => true, 'steps' => [ [ 'target' => 'wonderful-writer', @@ -208,6 +213,7 @@ private function register_badges() { $this->register_badge( 'streak_any_task', [ + 'public' => true, 'steps' => [ [ 'target' => 6, @@ -267,5 +273,44 @@ private function register_badges() { }, ] ); + + // Write a post for 10 consecutive weeks. + $this->register_badge( + 'personal_record_content', + [ + 'public' => false, + 'progress_callback' => function () { + $goal = new Goal_Recurring( + new Goal_Posts( + [ + 'id' => 'weekly_post', + 'title' => \esc_html__( 'Write a weekly blog post', 'progress-planner' ), + 'description' => \esc_html__( 'Streak: The number of weeks this goal has been accomplished consistently.', 'progress-planner' ), + 'status' => 'active', + 'priority' => 'low', + 'evaluate' => function ( $goal_object ) { + return (bool) count( + \progress_planner()->get_query()->query_activities( + [ + 'category' => 'content', + 'type' => 'publish', + 'start_date' => $goal_object->get_details()['start_date'], + 'end_date' => $goal_object->get_details()['end_date'], + ] + ) + ); + }, + ] + ), + 'weekly', + new \DateTime( '-2 years' ), // 2 years ago. + new \DateTime(), // Today. + 0 // Do not allow breaks in the streak. + ); + + return $goal->get_streak()['max_streak']; + }, + ] + ); } } diff --git a/views/admin-page.php b/views/admin-page.php index 989271bf7..c0b65804a 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -30,6 +30,7 @@ 'plugins', 'badge-content', 'badge-streak', + 'personal-record-content', ], [ 'latest-badge', diff --git a/views/widgets/activity-scores.php b/views/widgets/activity-scores.php index bcbc416c5..2ae0a6456 100644 --- a/views/widgets/activity-scores.php +++ b/views/widgets/activity-scores.php @@ -55,7 +55,7 @@ 'display' => false, ], ], - 'scales' => [ + 'scales' => [ 'yAxis' => [ 'min' => 0, 'max' => 100, diff --git a/views/widgets/badge-content.php b/views/widgets/badge-content.php index acd8176e1..28603c5f9 100644 --- a/views/widgets/badge-content.php +++ b/views/widgets/badge-content.php @@ -52,7 +52,7 @@ class="prpl-badge-gauge" --start: 180deg; --color: "> - +
% diff --git a/views/widgets/badge-streak.php b/views/widgets/badge-streak.php index b787d0170..fa30efee9 100644 --- a/views/widgets/badge-streak.php +++ b/views/widgets/badge-streak.php @@ -52,7 +52,7 @@ class="prpl-badge-gauge" --start: 180deg; --color: "> - +
% diff --git a/views/widgets/badges-progress.php b/views/widgets/badges-progress.php index e56b13037..18d470ee6 100644 --- a/views/widgets/badges-progress.php +++ b/views/widgets/badges-progress.php @@ -34,6 +34,11 @@

+
get_badges()->get_badge_progress( $prpl_badge['id'] ); ?> $prpl_badge_step_progress ) : ?> diff --git a/views/widgets/personal-record-content.php b/views/widgets/personal-record-content.php new file mode 100644 index 000000000..0ab7a1a06 --- /dev/null +++ b/views/widgets/personal-record-content.php @@ -0,0 +1,11 @@ +get_badges()->get_badge_progress( 'personal_record_content' ); + +echo '

'; +printf( + /* translators: %s: The number of weeks. */ + esc_html__( 'Personal record: %s weeks of writing content', 'progress-planner' ), + esc_html( $prpl_personal_record_content ) +); +echo '

'; From 065ab57e37d06a8c3d4ab0aef003705599ec0d5f Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 11 Mar 2024 13:33:55 +0200 Subject: [PATCH 177/490] don't require scanning when installing the plugin --- includes/admin/class-dashboard-widget.php | 24 ++++---------- includes/scan/class-content.php | 2 ++ views/admin-page.php | 40 +++++++++++------------ 3 files changed, 29 insertions(+), 37 deletions(-) diff --git a/includes/admin/class-dashboard-widget.php b/includes/admin/class-dashboard-widget.php index 7495fe7cd..8db9f854a 100644 --- a/includes/admin/class-dashboard-widget.php +++ b/includes/admin/class-dashboard-widget.php @@ -34,25 +34,15 @@ public function add_dashboard_widget() { * Render the dashboard widget. */ public function render_dashboard_widget() { - $scan_pending = empty( \progress_planner()->get_query()->query_activities( [] ) ); + // Enqueue Chart.js. + // TODO: Use a local copy of Chart.js and properly enqueue it. + echo ''; ?>
- -

- ' . esc_html__( 'the Progress Planner admin page', 'progress-planner' ) . '' - ) - ?> -

- - - - - - + + + +
$current_page, 'lastPage' => $total_pages, @@ -293,6 +294,7 @@ public static function reset_stats() { \progress_planner()->get_query()->delete_category_activities( 'content' ); \progress_planner()->get_query()->delete_category_activities( 'maintenance' ); \delete_option( static::LAST_SCANNED_PAGE_OPTION ); + \delete_option( 'progress_planner_content_scanned' ); } /** diff --git a/views/admin-page.php b/views/admin-page.php index c0b65804a..bce1cd306 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -7,7 +7,7 @@ namespace ProgressPlanner; -$prpl_scan_pending = null === \progress_planner()->get_query()->get_oldest_activity(); +$prpl_existing_content_scanned = get_option( 'progress_planner_content_scanned', false ); ?>

@@ -42,25 +42,25 @@ ?> - +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ - -
- -
- -
- -
- -
- -
- -
- -
- -
+
+ +
From 21e2ccfd6ec7d5f6c627291970efda90532e80ab Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 11 Mar 2024 14:44:12 +0200 Subject: [PATCH 178/490] Make gaps 32px --- assets/css/admin.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/css/admin.css b/assets/css/admin.css index eea5d5445..9be4890b9 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -2,7 +2,7 @@ Set variables. */ .prpl-wrap { - --prpl-gap: 20px; + --prpl-gap: 32px; --prpl-column-min-width: 20rem; --prpl-max-columns: 4; --prpl-border-radius: 7px; From f365c516dc4b3ce1a85c58824de93bd59a49e843 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 12 Mar 2024 09:56:56 +0200 Subject: [PATCH 179/490] increase columns width --- assets/css/admin.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/css/admin.css b/assets/css/admin.css index 9be4890b9..5fd1cab0a 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -3,7 +3,7 @@ Set variables. */ .prpl-wrap { --prpl-gap: 32px; - --prpl-column-min-width: 20rem; + --prpl-column-min-width: 22rem; --prpl-max-columns: 4; --prpl-border-radius: 7px; From 327eaf1f5ba992497c2c18b99d21f1595eb35b2b Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 12 Mar 2024 09:57:12 +0200 Subject: [PATCH 180/490] Introduce a Settings object --- includes/class-badges.php | 10 +--- includes/class-base.php | 5 +- includes/class-settings.php | 96 +++++++++++++++++++++++++++++++++ includes/scan/class-content.php | 14 ++--- views/admin-page.php | 6 ++- 5 files changed, 112 insertions(+), 19 deletions(-) create mode 100644 includes/class-settings.php diff --git a/includes/class-badges.php b/includes/class-badges.php index 1299d018c..eae469490 100644 --- a/includes/class-badges.php +++ b/includes/class-badges.php @@ -10,19 +10,13 @@ use ProgressPlanner\Goals\Goal_Recurring; use ProgressPlanner\Goals\Goal_Posts; use ProgressPlanner\Base; +use ProgressPlanner\Settings; /** * Badges class. */ class Badges { - /** - * The name of the badges option. - * - * @var string - */ - const OPTION_NAME = 'progress_planner_badges'; - /** * Registered badges. * @@ -41,7 +35,7 @@ class Badges { * Constructor. */ public function __construct() { - $this->badges_progress = \get_option( self::OPTION_NAME, [] ); + $this->badges_progress = Settings::get( 'badges', [] ); $this->register_badges(); } diff --git a/includes/class-base.php b/includes/class-base.php index 65028002f..41320c48d 100644 --- a/includes/class-base.php +++ b/includes/class-base.php @@ -12,6 +12,7 @@ use ProgressPlanner\Admin\Dashboard_Widget as Admin_Dashboard_Widget; use ProgressPlanner\Scan\Content as Scan_Content; use ProgressPlanner\Scan\Maintenance as Scan_Maintenance; +use ProgressPlanner\Settings; /** * Main plugin class. @@ -72,10 +73,10 @@ public function get_badges() { * @return \DateTime */ public static function get_activation_date() { - $activation_date = get_option( 'progress_planner_activation_date' ); + $activation_date = Settings::get( 'activation_date' ); if ( ! $activation_date ) { $activation_date = new \DateTime(); - update_option( 'progress_planner_activation_date', $activation_date->format( 'Y-m-d' ) ); + Settings::set( 'activation_date', $activation_date->format( 'Y-m-d' ) ); return $activation_date; } return \DateTime::createFromFormat( 'Y-m-d', $activation_date ); diff --git a/includes/class-settings.php b/includes/class-settings.php new file mode 100644 index 000000000..89d6ff5a4 --- /dev/null +++ b/includes/class-settings.php @@ -0,0 +1,96 @@ + $current_page, 'lastPage' => $total_pages, @@ -276,7 +277,7 @@ public static function update_stats() { $activities[ $post->ID ] = Content_Helpers::get_activity_from_post( $post ); } \progress_planner()->get_query()->insert_activities( $activities ); - \update_option( static::LAST_SCANNED_PAGE_OPTION, $current_page ); + Settings::set( static::LAST_SCANNED_PAGE_OPTION, $current_page ); return [ 'lastScannedPage' => $current_page, @@ -293,8 +294,7 @@ public static function update_stats() { public static function reset_stats() { \progress_planner()->get_query()->delete_category_activities( 'content' ); \progress_planner()->get_query()->delete_category_activities( 'maintenance' ); - \delete_option( static::LAST_SCANNED_PAGE_OPTION ); - \delete_option( 'progress_planner_content_scanned' ); + Settings::delete_all(); } /** diff --git a/views/admin-page.php b/views/admin-page.php index bce1cd306..453130afa 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -7,7 +7,9 @@ namespace ProgressPlanner; -$prpl_existing_content_scanned = get_option( 'progress_planner_content_scanned', false ); +use ProgressPlanner\Settings; + +$prpl_existing_content_scanned = Settings::get( 'content_scanned', false ); ?>

@@ -57,7 +59,7 @@
- +
From e01f2cdf8707d353d41495cd1a0eee7cb9f90005 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 12 Mar 2024 11:03:37 +0200 Subject: [PATCH 181/490] Save progress for badges --- includes/class-badges.php | 86 ++++++++++++++++++++++++++++++++++--- includes/class-settings.php | 23 +++++++--- 2 files changed, 99 insertions(+), 10 deletions(-) diff --git a/includes/class-badges.php b/includes/class-badges.php index eae469490..b30e6d1c0 100644 --- a/includes/class-badges.php +++ b/includes/class-badges.php @@ -140,6 +140,11 @@ private function register_badges() { ], ], 'progress_callback' => function ( $target ) { + $saved_progress = (int) Settings::get( [ 'badges', 'content_writing', $target, 'progress' ], 0 ); + if ( 100 === $saved_progress ) { + return 100; + } + // Evaluation for the "Wonderful writer" badge. if ( 'wonderful-writer' === $target ) { $existing_count = count( @@ -153,6 +158,15 @@ private function register_badges() { // Targeting 200 existing posts. $existing_progress = max( 100, floor( $existing_count / 2 ) ); if ( 100 <= $existing_progress ) { + if ( $saved_progress !== $existing_progress ) { + Settings::set( + [ 'badges', 'content_writing', $target, 'progress' ], + [ + 'progress' => 100, + 'date' => ( new \DateTime() )->format( 'Y-m-d H:i:s' ), + ] + ); + } return 100; } $new_count = count( @@ -166,8 +180,17 @@ private function register_badges() { ); // Targeting 10 new posts. $new_progress = max( 100, floor( $new_count * 10 ) ); - - return max( $existing_progress, $new_progress ); + $final = max( $existing_progress, $new_progress ); + if ( $saved_progress !== $final ) { + Settings::set( + [ 'badges', 'content_writing', $target, 'progress' ], + [ + 'progress' => $final, + 'date' => ( new \DateTime() )->format( 'Y-m-d H:i:s' ), + ] + ); + } + return $final; } // Evaluation for the "Awesome author" badge. @@ -181,8 +204,20 @@ private function register_badges() { ], ) ); + // Targeting 30 new posts. - return min( 100, floor( 100 * $new_count / 30 ) ); + $final = min( 100, floor( 100 * $new_count / 30 ) ); + + if ( $saved_progress !== $final ) { + Settings::set( + [ 'badges', 'content_writing', $target, 'progress' ], + [ + 'progress' => $final, + 'date' => ( new \DateTime() )->format( 'Y-m-d H:i:s' ), + ] + ); + } + return $final; } // Evaluation for the "Notorious novelist" badge. @@ -197,7 +232,17 @@ private function register_badges() { ) ); // Targeting 50 new posts. - return min( 100, floor( 50 * $new_count / 100 ) ); + $final = min( 100, floor( 50 * $new_count / 100 ) ); + if ( $saved_progress !== $final ) { + Settings::set( + [ 'badges', 'content_writing', $target, 'progress' ], + [ + 'progress' => $final, + 'date' => ( new \DateTime() )->format( 'Y-m-d H:i:s' ), + ] + ); + } + return $final; } }, ] @@ -263,7 +308,23 @@ private function register_badges() { 1 // Allow break in the streak for 1 week. ); - return min( floor( 100 * $goal->get_streak()['max_streak'] / $target ), 100 ); + $saved_progress = (int) Settings::get( [ 'badges', 'streak_any_task', $target, 'progress' ], 0 ); + if ( 100 === $saved_progress ) { + return 100; + } + + $final = min( floor( 100 * $goal->get_streak()['max_streak'] / $target ), 100 ); + + if ( $saved_progress !== $final ) { + Settings::set( + [ 'badges', 'streak_any_task', $target, 'progress' ], + [ + 'progress' => $final, + 'date' => ( new \DateTime() )->format( 'Y-m-d H:i:s' ), + ] + ); + } + return $final; }, ] ); @@ -302,6 +363,21 @@ private function register_badges() { 0 // Do not allow breaks in the streak. ); + $saved_progress = Settings::get( [ 'badges', 'personal_record_content', 'date' ], false ); + // If the date is set and shorter than 2 days, return it without querying. + if ( $saved_progress && ( new \DateTime() )->diff( new \DateTime( $saved_progress ) )->days < 2 ) { + return Settings::get( [ 'badges', 'personal_record_content', 'progress' ], 0 ); + } + + $final = $goal->get_streak()['max_streak']; + Settings::set( + [ 'badges', 'personal_record_content' ], + [ + 'progress' => $final, + 'date' => ( new \DateTime() )->format( 'Y-m-d H:i:s' ), + ] + ); + return $goal->get_streak()['max_streak']; }, ] diff --git a/includes/class-settings.php b/includes/class-settings.php index 89d6ff5a4..cdee1ebbb 100644 --- a/includes/class-settings.php +++ b/includes/class-settings.php @@ -29,27 +29,40 @@ class Settings { /** * Get the value of a setting. * - * @param string $setting The setting. - * @param mixed $default_value The default value. + * @param string|array $setting The setting. + * If a string, the name of the setting. + * If an array, get value recursively from the settings. + * See _wp_array_get() for more information. + * @param mixed $default_value The default value. * * @return mixed The value of the setting. */ public static function get( $setting, $default_value = null ) { self::load_settings(); + if ( is_array( $setting ) ) { + return \_wp_array_get( self::$settings, $setting, $default_value ); + } return self::$settings[ $setting ] ?? $default_value; } /** * Set the value of a setting. * - * @param string $setting The setting. - * @param mixed $value The value. + * @param string|array $setting The setting. + * If a string, the name of the setting. + * If an array, set value recursively in the settings. + * See _wp_array_set() for more information. + * @param mixed $value The value. * * @return void */ public static function set( $setting, $value ) { self::load_settings(); - self::$settings[ $setting ] = $value; + if ( is_array( $setting ) ) { + \_wp_array_set( self::$settings, $setting, $value ); + } else { + self::$settings[ $setting ] = $value; + } self::save_settings(); } From f435a1203aef6680c9d01b298e78cc8c33868b0c Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 12 Mar 2024 11:13:33 +0200 Subject: [PATCH 182/490] backward-compatibility for test sites --- includes/class-settings.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/includes/class-settings.php b/includes/class-settings.php index cdee1ebbb..a5230721a 100644 --- a/includes/class-settings.php +++ b/includes/class-settings.php @@ -39,6 +39,12 @@ class Settings { */ public static function get( $setting, $default_value = null ) { self::load_settings(); + + // TODO: DELETE THIS PART. It's here for backward compatibility on test sites. + if ( 'activation_date' === $setting ) { + return \get_option( 'progress_planner_activation_date' ); + } + if ( is_array( $setting ) ) { return \_wp_array_get( self::$settings, $setting, $default_value ); } From f928b0b6fc471cc0b4e1e580314660dc6f8919d6 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 12 Mar 2024 11:40:52 +0200 Subject: [PATCH 183/490] fix badges setting saved value --- includes/class-badges.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/includes/class-badges.php b/includes/class-badges.php index b30e6d1c0..894a31b37 100644 --- a/includes/class-badges.php +++ b/includes/class-badges.php @@ -160,7 +160,7 @@ private function register_badges() { if ( 100 <= $existing_progress ) { if ( $saved_progress !== $existing_progress ) { Settings::set( - [ 'badges', 'content_writing', $target, 'progress' ], + [ 'badges', 'content_writing', $target ], [ 'progress' => 100, 'date' => ( new \DateTime() )->format( 'Y-m-d H:i:s' ), @@ -183,7 +183,7 @@ private function register_badges() { $final = max( $existing_progress, $new_progress ); if ( $saved_progress !== $final ) { Settings::set( - [ 'badges', 'content_writing', $target, 'progress' ], + [ 'badges', 'content_writing', $target ], [ 'progress' => $final, 'date' => ( new \DateTime() )->format( 'Y-m-d H:i:s' ), @@ -210,7 +210,7 @@ private function register_badges() { if ( $saved_progress !== $final ) { Settings::set( - [ 'badges', 'content_writing', $target, 'progress' ], + [ 'badges', 'content_writing', $target ], [ 'progress' => $final, 'date' => ( new \DateTime() )->format( 'Y-m-d H:i:s' ), @@ -235,7 +235,7 @@ private function register_badges() { $final = min( 100, floor( 50 * $new_count / 100 ) ); if ( $saved_progress !== $final ) { Settings::set( - [ 'badges', 'content_writing', $target, 'progress' ], + [ 'badges', 'content_writing', $target ], [ 'progress' => $final, 'date' => ( new \DateTime() )->format( 'Y-m-d H:i:s' ), @@ -317,7 +317,7 @@ private function register_badges() { if ( $saved_progress !== $final ) { Settings::set( - [ 'badges', 'streak_any_task', $target, 'progress' ], + [ 'badges', 'streak_any_task', $target ], [ 'progress' => $final, 'date' => ( new \DateTime() )->format( 'Y-m-d H:i:s' ), From 22184ca4e89d860c2cc755d7f27c4382e5fbb95b Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 12 Mar 2024 11:41:08 +0200 Subject: [PATCH 184/490] CS --- views/admin-page.php | 2 +- views/widgets/personal-record-content.php | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/views/admin-page.php b/views/admin-page.php index 453130afa..5de50719a 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -63,6 +63,6 @@
- +
diff --git a/views/widgets/personal-record-content.php b/views/widgets/personal-record-content.php index 0ab7a1a06..f7f8bc332 100644 --- a/views/widgets/personal-record-content.php +++ b/views/widgets/personal-record-content.php @@ -1,4 +1,11 @@ get_badges()->get_badge_progress( 'personal_record_content' ); From 5c68e5e607bf07a387ee37a9111ca45166e0bdac Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 12 Mar 2024 11:41:33 +0200 Subject: [PATCH 185/490] Figure out what the latest earned badge is --- views/widgets/latest-badge.php | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/views/widgets/latest-badge.php b/views/widgets/latest-badge.php index ea7164443..8eba06276 100644 --- a/views/widgets/latest-badge.php +++ b/views/widgets/latest-badge.php @@ -7,7 +7,48 @@ namespace ProgressPlanner; +use ProgressPlanner\Settings; + +// Get the settings for badges. +$prpl_badges_settings = Settings::get( 'badges' ); +$prpl_latest_badge_date = null; +$prpl_latest_badge_details = null; +foreach ( $prpl_badges_settings as $prpl_badge_id => $prpl_badge_settings ) { + foreach ( $prpl_badge_settings as $prpl_badge_target => $prpl_badge_progress ) { + if ( isset( $prpl_badge_progress['progress'] ) && 100 === $prpl_badge_progress['progress'] ) { + if ( null === $prpl_latest_badge_date || + \DateTime::createFromFormat( 'Y-m-d H:i:s', $prpl_badge_progress['date'] )->format( 'U' ) > \DateTime::createFromFormat( 'Y-m-d H:i:s', $prpl_latest_badge_date )->format( 'U' ) + ) { + $prpl_latest_badge_date = $prpl_badge_progress['date']; + $prpl_latest_badge_details = [ $prpl_badge_id, $prpl_badge_target ]; + } + } + } +} + +if ( $prpl_latest_badge_details ) { + $prpl_latest_badge = \progress_planner()->get_badges()->get_badge( $prpl_latest_badge_details[0] ); + foreach ( $prpl_latest_badge['steps'] as $prpl_badge_step ) { + if ( $prpl_badge_step['target'] === $prpl_latest_badge_details[1] ) { + $prpl_latest_badge = $prpl_badge_step; + break; + } + } +} ?>

+ +

+ +

+ ' . esc_html( $prpl_latest_badge['name'] ) . '' + ); + ?> +

+ From 32ed3cce48b47ca3213d69de57762867236e6a67 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 12 Mar 2024 12:29:58 +0200 Subject: [PATCH 186/490] Improve Settings class --- includes/class-settings.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/includes/class-settings.php b/includes/class-settings.php index a5230721a..18ac8267d 100644 --- a/includes/class-settings.php +++ b/includes/class-settings.php @@ -60,7 +60,7 @@ public static function get( $setting, $default_value = null ) { * See _wp_array_set() for more information. * @param mixed $value The value. * - * @return void + * @return bool */ public static function set( $setting, $value ) { self::load_settings(); @@ -69,7 +69,7 @@ public static function set( $setting, $value ) { } else { self::$settings[ $setting ] = $value; } - self::save_settings(); + return self::save_settings(); } /** @@ -78,16 +78,19 @@ public static function set( $setting, $value ) { * @return void */ private static function load_settings() { + if ( ! empty( self::$settings ) ) { + return; + } self::$settings = \get_option( self::OPTION_NAME, [] ); } /** * Save the settings. * - * @return void + * @return bool */ private static function save_settings() { - \update_option( self::OPTION_NAME, self::$settings, false ); + return \update_option( self::OPTION_NAME, self::$settings, false ); } /** @@ -95,21 +98,21 @@ private static function save_settings() { * * @param string $setting The setting. * - * @return void + * @return bool */ public static function delete( $setting ) { self::load_settings(); unset( self::$settings[ $setting ] ); - self::save_settings(); + return self::save_settings(); } /** * Delete all settings. * - * @return void + * @return bool */ public static function delete_all() { self::$settings = []; - self::save_settings(); + return self::save_settings(); } } From f72b15597e354daa6ea0a218f3758750cb5fe15c Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 12 Mar 2024 12:58:23 +0200 Subject: [PATCH 187/490] CSS tweaks --- assets/css/admin.css | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/assets/css/admin.css b/assets/css/admin.css index 5fd1cab0a..08ff2ef2e 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -3,11 +3,13 @@ Set variables. */ .prpl-wrap { --prpl-gap: 32px; - --prpl-column-min-width: 22rem; + --prpl-padding: 20px; + --prpl-column-min-width: 16rem; + --prpl-column-max-width: 30rem; --prpl-max-columns: 4; --prpl-border-radius: 7px; - --prpl-container-max-width: calc(var(--prpl-column-min-width) * var(--prpl-max-columns) + var(--prpl-gap) * (var(--prpl-max-columns) - 1)); + --prpl-container-max-width: calc(var(--prpl-column-max-width) * var(--prpl-max-columns) + var(--prpl-gap) * (var(--prpl-max-columns) - 1)); --prpl-color-gray-1: #e5e7eb; --prpl-color-gray-2: #d1d5db; @@ -34,6 +36,7 @@ Set variables. --prpl-background-red: #fff6f7; --prpl-background-blue: #effbfe; + --prpl-font-size-xs: 0.75rem; /* 12px */ --prpl-font-size-small: 0.875rem; /* 14px */ --prpl-font-size-base: 1rem; /* 16px */ --prpl-font-size-lg: 1.125rem; /* 18px */ @@ -48,8 +51,8 @@ Set variables. background: #fff; border: 1px solid var(--prpl-color-gray-3); border-radius: var(--prpl-border-radius); - padding: var(--prpl-gap); - /* max-width: var(--prpl-container-max-width); */ + padding: var(--prpl-padding); + max-width: var(--prpl-container-max-width); color: var(--prpl-color-text); font-size: var(--prpl-font-size-base); line-height: 1.4 @@ -80,7 +83,7 @@ Set variables. .prpl-widgets-container { display: grid; - grid-template-columns: repeat(auto-fit, minmax(var(--prpl-column-min-width), 1fr)); + grid-template-columns: repeat(auto-fit, minmax(calc(var(--prpl-column-min-width) * 2), 1fr)); grid-gap: var(--prpl-gap); } @@ -105,14 +108,14 @@ Set variables. .prpl-widget-wrapper { border: 1px solid var(--prpl-color-gray-2); border-radius: var(--prpl-border-radius); - padding: var(--prpl-gap); + padding: var(--prpl-padding); display: flex; flex-direction: column; } .prpl-wrap .counter-big-wrapper { background-color: var(--prpl-background-purple); - padding: var(--prpl-gap); + padding: var(--prpl-padding); border-radius: var(--prpl-border-radius); display: flex; flex-direction: column; @@ -167,13 +170,13 @@ Set variables. .prpl-widget-wrapper.prpl-badges-progress .progress-wrapper { display: grid; grid-template-columns: 1fr 1fr 1fr; - grid-gap: var(--prpl-gap); + grid-gap: calc(var(--prpl-gap) / 2); } .prpl-widget-wrapper.prpl-published-content table { width: 100%; margin-bottom: 1em; - padding: calc(var(--prpl-gap) / 2) 0; + padding: var(--prpl-padding) 0; /* border: 1px solid var(--prpl-color-gray-2); */ /* border-radius: var(--prpl-border-radius); */ border-top: 1px solid var(--prpl-color-gray-3); @@ -196,7 +199,7 @@ Set variables. .prpl-badges-columns-wrapper { display: grid; grid-template-columns: 1fr 1fr; - grid-gap: var(--prpl-gap); + grid-gap: var(--prpl-padding); } .prpl-badge-gauge, @@ -221,7 +224,7 @@ Set variables. } .prpl-activities-gauge-container { - padding: var(--prpl-gap); + padding: var(--prpl-padding); background: var(--prpl-background-orange); border-radius: var(--prpl-border-radius); aspect-ratio: 1 / 1; @@ -244,7 +247,7 @@ Set variables. .prpl-badge-wrapper { background: var(--prpl-background-blue); - padding: var(--prpl-gap); + padding: var(--prpl-padding); border-radius: var(--prpl-border-radius); } @@ -260,14 +263,14 @@ Set variables. .prpl-widget-wrapper.prpl-badges-progress .progress-wrapper { background-color: var(--prpl-background-blue); - padding: calc(var(--prpl-gap) / 2); + padding: calc(var(--prpl-padding) / 2); border-radius: var(--prpl-border-radius); - margin-bottom: var(--prpl-gap); + margin-bottom: var(--prpl-padding); } .prpl-widget-wrapper.prpl-badges-progress .progress-wrapper p { margin: 0; - font-size:var(--prpl-font-size-small); + font-size:var(--prpl-font-size-xs); text-align:center; } From 901c7b9cfb87d77b67def943efe54dab1497d113 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 12 Mar 2024 13:16:18 +0200 Subject: [PATCH 188/490] More CSS tweaks --- assets/css/admin.css | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/assets/css/admin.css b/assets/css/admin.css index 08ff2ef2e..c92a0958d 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -51,7 +51,7 @@ Set variables. background: #fff; border: 1px solid var(--prpl-color-gray-3); border-radius: var(--prpl-border-radius); - padding: var(--prpl-padding); + padding: calc(var(--prpl-padding) * 2); max-width: var(--prpl-container-max-width); color: var(--prpl-color-text); font-size: var(--prpl-font-size-base); @@ -77,7 +77,6 @@ Set variables. #progress-planner-scan-progress progress { width: 100%; - max-width: 500px; min-height: 1px; } @@ -168,9 +167,17 @@ Set variables. } .prpl-widget-wrapper.prpl-badges-progress .progress-wrapper { - display: grid; - grid-template-columns: 1fr 1fr 1fr; - grid-gap: calc(var(--prpl-gap) / 2); + display: flex; + gap: calc(var(--prpl-gap) / 2); + justify-content: space-between; +} + +.prpl-widget-wrapper.prpl-badges-progress .progress-wrapper .prpl-badge { + display: flex; + flex-direction: column; + align-items: center; + justify-content: space-between; + flex-wrap: wrap; } .prpl-widget-wrapper.prpl-published-content table { From d165379586126cb6a6c5798d0c272ce9410ec14f Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 12 Mar 2024 13:45:23 +0200 Subject: [PATCH 189/490] Better definition of badge icons --- assets/css/admin.css | 7 +++- includes/class-badges.php | 60 ++++++++++++++++++++++++------- views/widgets/badge-content.php | 2 +- views/widgets/badge-streak.php | 2 +- views/widgets/badges-progress.php | 4 +-- 5 files changed, 58 insertions(+), 17 deletions(-) diff --git a/assets/css/admin.css b/assets/css/admin.css index c92a0958d..d39b4eec5 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -169,7 +169,8 @@ Set variables. .prpl-widget-wrapper.prpl-badges-progress .progress-wrapper { display: flex; gap: calc(var(--prpl-gap) / 2); - justify-content: space-between; + justify-content: center; + flex-wrap: wrap; } .prpl-widget-wrapper.prpl-badges-progress .progress-wrapper .prpl-badge { @@ -180,6 +181,10 @@ Set variables. flex-wrap: wrap; } +.prpl-widget-wrapper.prpl-badges-progress .progress-wrapper .prpl-badge > svg { + width: 100px; +} + .prpl-widget-wrapper.prpl-published-content table { width: 100%; margin-bottom: 1em; diff --git a/includes/class-badges.php b/includes/class-badges.php index 894a31b37..42f6bcec1 100644 --- a/includes/class-badges.php +++ b/includes/class-badges.php @@ -118,24 +118,42 @@ private function register_badges() { 'target' => 'wonderful-writer', 'name' => __( 'Wonderful Writer', 'progress-planner' ), 'icons-svg' => [ - \PROGRESS_PLANNER_DIR . '/assets/images/badges/writing_badge1_gray.svg', - \PROGRESS_PLANNER_DIR . '/assets/images/badges/writing_badge1.svg', + 'pending' => [ + 'path' => \PROGRESS_PLANNER_DIR . '/assets/images/badges/writing_badge1_gray.svg', + 'url' => \PROGRESS_PLANNER_URL . '/assets/images/badges/writing_badge1_gray.svg', + ], + 'complete' => [ + 'path' => \PROGRESS_PLANNER_DIR . '/assets/images/badges/writing_badge1.svg', + 'url' => \PROGRESS_PLANNER_URL . '/assets/images/badges/writing_badge1.svg', + ], ], ], [ 'target' => 'awesome-author', 'name' => __( 'Awesome Author', 'progress-planner' ), 'icons-svg' => [ - \PROGRESS_PLANNER_DIR . '/assets/images/badges/writing_badge2_gray.svg', - \PROGRESS_PLANNER_DIR . '/assets/images/badges/writing_badge2.svg', + 'pending' => [ + 'path' => \PROGRESS_PLANNER_DIR . '/assets/images/badges/writing_badge2_gray.svg', + 'url' => \PROGRESS_PLANNER_URL . '/assets/images/badges/writing_badge2_gray.svg', + ], + 'complete' => [ + 'path' => \PROGRESS_PLANNER_DIR . '/assets/images/badges/writing_badge2.svg', + 'url' => \PROGRESS_PLANNER_URL . '/assets/images/badges/writing_badge2.svg', + ], ], ], [ 'target' => 'notorious-novelist', 'name' => __( 'Notorious Novelist', 'progress-planner' ), 'icons-svg' => [ - \PROGRESS_PLANNER_DIR . '/assets/images/badges/writing_badge3_gray.svg', - \PROGRESS_PLANNER_DIR . '/assets/images/badges/writing_badge3.svg', + 'pending' => [ + 'path' => \PROGRESS_PLANNER_DIR . '/assets/images/badges/writing_badge3_gray.svg', + 'url' => \PROGRESS_PLANNER_URL . '/assets/images/badges/writing_badge3_gray.svg', + ], + 'complete' => [ + 'path' => \PROGRESS_PLANNER_DIR . '/assets/images/badges/writing_badge3.svg', + 'url' => \PROGRESS_PLANNER_URL . '/assets/images/badges/writing_badge3.svg', + ], ], ], ], @@ -258,24 +276,42 @@ private function register_badges() { 'target' => 6, 'name' => __( 'Progress Professional', 'progress-planner' ), 'icons-svg' => [ - \PROGRESS_PLANNER_DIR . '/assets/images/badges/streak_badge1_gray.svg', - \PROGRESS_PLANNER_DIR . '/assets/images/badges/streak_badge1.svg', + 'pending' => [ + 'path' => \PROGRESS_PLANNER_DIR . '/assets/images/badges/streak_badge1_gray.svg', + 'url' => \PROGRESS_PLANNER_URL . '/assets/images/badges/streak_badge1_gray.svg', + ], + 'complete' => [ + 'path' => \PROGRESS_PLANNER_DIR . '/assets/images/badges/streak_badge1.svg', + 'url' => \PROGRESS_PLANNER_URL . '/assets/images/badges/streak_badge1.svg', + ], ], ], [ 'target' => 26, 'name' => __( 'Maintenance Maniac', 'progress-planner' ), 'icons-svg' => [ - \PROGRESS_PLANNER_DIR . '/assets/images/badges/streak_badge2_gray.svg', - \PROGRESS_PLANNER_DIR . '/assets/images/badges/streak_badge2.svg', + 'pending' => [ + 'path' => \PROGRESS_PLANNER_DIR . '/assets/images/badges/streak_badge2_gray.svg', + 'url' => \PROGRESS_PLANNER_URL . '/assets/images/badges/streak_badge2_gray.svg', + ], + 'complete' => [ + 'path' => \PROGRESS_PLANNER_DIR . '/assets/images/badges/streak_badge2.svg', + 'url' => \PROGRESS_PLANNER_URL . '/assets/images/badges/streak_badge2.svg', + ], ], ], [ 'target' => 52, 'name' => __( 'Super Site Specialist', 'progress-planner' ), 'icons-svg' => [ - \PROGRESS_PLANNER_DIR . '/assets/images/badges/streak_badge3_gray.svg', - \PROGRESS_PLANNER_DIR . '/assets/images/badges/streak_badge3.svg', + 'pending' => [ + 'path' => \PROGRESS_PLANNER_DIR . '/assets/images/badges/streak_badge3_gray.svg', + 'url' => \PROGRESS_PLANNER_URL . '/assets/images/badges/streak_badge3_gray.svg', + ], + 'complete' => [ + 'path' => \PROGRESS_PLANNER_DIR . '/assets/images/badges/streak_badge3.svg', + 'url' => \PROGRESS_PLANNER_URL . '/assets/images/badges/streak_badge3.svg', + ], ], ], ], diff --git a/views/widgets/badge-content.php b/views/widgets/badge-content.php index 28603c5f9..4e079ae28 100644 --- a/views/widgets/badge-content.php +++ b/views/widgets/badge-content.php @@ -52,7 +52,7 @@ class="prpl-badge-gauge" --start: 180deg; --color: "> - +
% diff --git a/views/widgets/badge-streak.php b/views/widgets/badge-streak.php index fa30efee9..343599d9c 100644 --- a/views/widgets/badge-streak.php +++ b/views/widgets/badge-streak.php @@ -52,7 +52,7 @@ class="prpl-badge-gauge" --start: 180deg; --color: "> - +
% diff --git a/views/widgets/badges-progress.php b/views/widgets/badges-progress.php index 18d470ee6..25c640994 100644 --- a/views/widgets/badges-progress.php +++ b/views/widgets/badges-progress.php @@ -49,8 +49,8 @@ class="prpl-badge" >

From 934ae0362eb908dee47261af4578e56d82e66e15 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 15 Mar 2024 09:45:30 +0200 Subject: [PATCH 190/490] cleanup & style tweaks --- .gitignore | 1 + assets/css/admin.css | 163 ++++++++++++------ includes/activities/class-content-helpers.php | 1 + includes/scan/class-maintenance.php | 3 - views/widgets/published-content.php | 78 ++++----- 5 files changed, 149 insertions(+), 97 deletions(-) diff --git a/.gitignore b/.gitignore index 96fd02697..c844c2920 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ vendor/ composer.lock +._* diff --git a/assets/css/admin.css b/assets/css/admin.css index d39b4eec5..d2cf48869 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -1,6 +1,6 @@ -/* -Set variables. -*/ +/*------------------------------------*\ + Set variables. +\*------------------------------------*/ .prpl-wrap { --prpl-gap: 32px; --prpl-padding: 20px; @@ -47,6 +47,9 @@ Set variables. --prpl-font-size-5xl: 4rem; /* 64px */ } +/*------------------------------------*\ + Styles for the container of the page. +\*------------------------------------*/ .prpl-wrap { background: #fff; border: 1px solid var(--prpl-color-gray-3); @@ -58,6 +61,9 @@ Set variables. line-height: 1.4 } +/*------------------------------------*\ + Generic styles. +\*------------------------------------*/ .prpl-wrap p { font-size: var(--prpl-font-size-base); } @@ -75,11 +81,26 @@ Set variables. color: var(--prpl-color-link); } +/*------------------------------------*\ + Charts container. +\*------------------------------------*/ +.prpl-chart-container { + position: relative; + height: 100%; + max-height: 500px; +} + +/*------------------------------------*\ + Progress bar styles for the posts scanner. +\*------------------------------------*/ #progress-planner-scan-progress progress { width: 100%; min-height: 1px; } +/*------------------------------------*\ + Layout for widgets. +\*------------------------------------*/ .prpl-widgets-container { display: grid; grid-template-columns: repeat(auto-fit, minmax(calc(var(--prpl-column-min-width) * 2), 1fr)); @@ -98,12 +119,18 @@ Set variables. gap: var(--prpl-gap); } +/*------------------------------------*\ + Widgets with 2 columns. +\*------------------------------------*/ .two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(var(--prpl-column-min-width), 1fr)); - grid-gap: var(--prpl-gap); + grid-gap: var(--prpl-padding); } +/*------------------------------------*\ + Generic styles for individual widgets. +\*------------------------------------*/ .prpl-widget-wrapper { border: 1px solid var(--prpl-color-gray-2); border-radius: var(--prpl-border-radius); @@ -112,6 +139,9 @@ Set variables. flex-direction: column; } +/*------------------------------------*\ + The big counters in widgets. +\*------------------------------------*/ .prpl-wrap .counter-big-wrapper { background-color: var(--prpl-background-purple); padding: var(--prpl-padding); @@ -131,11 +161,18 @@ Set variables. font-size: var(--prpl-font-size-2xl); } +/*------------------------------------*\ + Generic styles for the graph wrappers. +\*------------------------------------*/ .prpl-graph-wrapper { position: relative; height: 100%; } +/*------------------------------------*\ + The wrapper for widgets that have a + big counter at the top, and content at the bottom. +\*------------------------------------*/ .prpl-top-counter-bottom-content { display: flex; flex-direction: column; @@ -148,7 +185,10 @@ Set variables. justify-content: center; } -.progress-percent { +/*------------------------------------*\ + Percent display for badges. +\*------------------------------------*/ +.prpl-badge-wrapper .progress-percent { font-size: var(--prpl-font-size-3xl); line-height: 1; font-weight: 600; @@ -156,12 +196,40 @@ Set variables. text-align: center; } -.prpl-gauge-number { +/*------------------------------------*\ + Activity-score widget. +\*------------------------------------*/ +.prpl-widget-wrapper.prpl-website-activity-score .two-col { + grid-template-columns: 6fr 4fr; +} + +.prpl-widget-wrapper.prpl-website-activity-score .prpl-gauge-number { font-size: var(--prpl-font-size-4xl); line-height: 1; margin-top: -1em; } +.prpl-activities-gauge-container { + padding: var(--prpl-padding); + background: var(--prpl-background-orange); + border-radius: var(--prpl-border-radius); + aspect-ratio: 1 / 1; + top: 50%; +} + +.prpl-activities-gauge-container .prpl-gauge-number { + display: block; + padding-top: 50%; + font-weight: 700; + text-align: center; + position: absolute; + width: 100%; + line-height: 2; +} + +/*------------------------------------*\ + Badges progress widget. +\*------------------------------------*/ .prpl-widget-wrapper.prpl-badges-progress .progress-label { display: inline-block; } @@ -185,12 +253,34 @@ Set variables. width: 100px; } +.prpl-widget-wrapper.prpl-badges-progress .progress-wrapper { + background-color: var(--prpl-background-blue); + padding: calc(var(--prpl-padding) / 2); + border-radius: var(--prpl-border-radius); + margin-bottom: var(--prpl-padding); +} + +.prpl-widget-wrapper.prpl-badges-progress .progress-wrapper p { + margin: 0; + font-size:var(--prpl-font-size-xs); + text-align:center; +} + +.prpl-widget-wrapper.prpl-badges-progress .progress-wrapper + .progress-wrapper { + background-color: var(--prpl-background-orange); +} + +/*------------------------------------*\ + Published content widget. +\*------------------------------------*/ +.prpl-widget-wrapper.prpl-published-content .two-col { + align-items: flex-start; +} + .prpl-widget-wrapper.prpl-published-content table { width: 100%; margin-bottom: 1em; padding: var(--prpl-padding) 0; - /* border: 1px solid var(--prpl-color-gray-2); */ - /* border-radius: var(--prpl-border-radius); */ border-top: 1px solid var(--prpl-color-gray-3); border-bottom: 1px solid var(--prpl-color-gray-3); } @@ -199,15 +289,23 @@ Set variables. text-align: start; } -.prpl-widget-wrapper.prpl-published-content td { +.prpl-widget-wrapper.prpl-published-content th:not(:first-child), +.prpl-widget-wrapper.prpl-published-content td:not(:first-child) { padding: 0.5em; - border-bottom: 1px solid var(--prpl-color-gray-1); + text-align: center; +} + +.prpl-widget-wrapper.prpl-published-content tr:nth-child(even) { + background-color: var(--prpl-background-purple); } .prpl-widget-wrapper.prpl-published-content tr:last-child td { border-bottom: none; } +/*------------------------------------*\ + Individual badge widgets. +\*------------------------------------*/ .prpl-badges-columns-wrapper { display: grid; grid-template-columns: 1fr 1fr; @@ -235,24 +333,6 @@ Set variables. text-align: center; } -.prpl-activities-gauge-container { - padding: var(--prpl-padding); - background: var(--prpl-background-orange); - border-radius: var(--prpl-border-radius); - aspect-ratio: 1 / 1; - top: 50%; -} - -.prpl-activities-gauge-container .prpl-gauge-number { - display: block; - padding-top: 50%; - font-weight: 700; - text-align: center; - position: absolute; - width: 100%; - line-height: 2; -} - .prpl-badge-gauge svg { aspect-ratio: 1.15; } @@ -262,30 +342,3 @@ Set variables. padding: var(--prpl-padding); border-radius: var(--prpl-border-radius); } - -.prpl-chart-container { - position: relative; - height: 100%; - max-height: 500px; -} - -.prpl-widget-wrapper.prpl-badge-streak .prpl-badge-wrapper { - background-color: var(--prpl-background-orange); -} - -.prpl-widget-wrapper.prpl-badges-progress .progress-wrapper { - background-color: var(--prpl-background-blue); - padding: calc(var(--prpl-padding) / 2); - border-radius: var(--prpl-border-radius); - margin-bottom: var(--prpl-padding); -} - -.prpl-widget-wrapper.prpl-badges-progress .progress-wrapper p { - margin: 0; - font-size:var(--prpl-font-size-xs); - text-align:center; -} - -.prpl-widget-wrapper.prpl-badges-progress .progress-wrapper + .progress-wrapper { - background-color: var(--prpl-background-orange); -} diff --git a/includes/activities/class-content-helpers.php b/includes/activities/class-content-helpers.php index 918abbbbb..94f43ea42 100644 --- a/includes/activities/class-content-helpers.php +++ b/includes/activities/class-content-helpers.php @@ -34,6 +34,7 @@ public static function get_post_types_names() { * and strip HTML before counting the words. * * @param string $content The content. + * @param int $post_id The post ID. Used for caching the number of words per post. * * @return int */ diff --git a/includes/scan/class-maintenance.php b/includes/scan/class-maintenance.php index 13dc97cd3..54e02aeb7 100644 --- a/includes/scan/class-maintenance.php +++ b/includes/scan/class-maintenance.php @@ -93,9 +93,6 @@ public function on_delete_plugin() { /** * On delete theme. * - * @param string $theme The theme. - * @param bool $deleted Whether the theme was deleted. - * * @return void */ public function on_delete_theme() { diff --git a/views/widgets/published-content.php b/views/widgets/published-content.php index 27ae2d0bc..5a08aa0ff 100644 --- a/views/widgets/published-content.php +++ b/views/widgets/published-content.php @@ -62,46 +62,46 @@ ?>

- - - - - - - - - - - - - - - - - -
labels->name ); ?>
-
-
- the_chart( - [ - 'query_params' => [ - 'category' => 'content', - 'type' => 'publish', - ], - 'dates_params' => [ - 'start' => \DateTime::createFromFormat( 'Y-m-d', \gmdate( 'Y-m-01' ) )->modify( $prpl_active_range ), - 'end' => new \DateTime(), - 'frequency' => $prpl_active_frequency, - 'format' => 'M', - ], - 'chart_params' => [ - 'type' => 'line', +
+ the_chart( + [ + 'query_params' => [ + 'category' => 'content', + 'type' => 'publish', + ], + 'dates_params' => [ + 'start' => \DateTime::createFromFormat( 'Y-m-d', \gmdate( 'Y-m-01' ) )->modify( $prpl_active_range ), + 'end' => new \DateTime(), + 'frequency' => $prpl_active_frequency, + 'format' => 'M', + ], + 'chart_params' => [ + 'type' => 'line', + ], + 'additive' => true, ], - 'additive' => true, - ], - ); - ?> + ); + ?> +
+ + + + + + + + + + + + + + + + + +
labels->name ); ?>
From e321be0c4e76695e0d2aa51d880ddd4a4a9033bc Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 15 Mar 2024 10:34:28 +0200 Subject: [PATCH 191/490] Add personal-record widget --- assets/css/admin.css | 7 ++++ includes/class-badges.php | 10 ++--- views/admin-page.php | 2 +- views/widgets/personal-record-content.php | 49 +++++++++++++++++++---- 4 files changed, 55 insertions(+), 13 deletions(-) diff --git a/assets/css/admin.css b/assets/css/admin.css index d2cf48869..8dbdf42ee 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -342,3 +342,10 @@ padding: var(--prpl-padding); border-radius: var(--prpl-border-radius); } + +/*------------------------------------*\ + Personal record widget. +\*------------------------------------*/ +.prpl-widget-wrapper.prpl-personal-record-content .counter-big-wrapper { + background-color: var(--prpl-background-green); +} diff --git a/includes/class-badges.php b/includes/class-badges.php index 42f6bcec1..cfd911275 100644 --- a/includes/class-badges.php +++ b/includes/class-badges.php @@ -399,13 +399,13 @@ private function register_badges() { 0 // Do not allow breaks in the streak. ); - $saved_progress = Settings::get( [ 'badges', 'personal_record_content', 'date' ], false ); + $saved_progress = Settings::get( [ 'badges', 'personal_record_content' ], false ); // If the date is set and shorter than 2 days, return it without querying. - if ( $saved_progress && ( new \DateTime() )->diff( new \DateTime( $saved_progress ) )->days < 2 ) { - return Settings::get( [ 'badges', 'personal_record_content', 'progress' ], 0 ); + if ( $saved_progress && is_array( $saved_progress['progress'] ) && ( new \DateTime() )->diff( new \DateTime( $saved_progress['date'] ) )->days < 2 ) { + return $saved_progress['progress']; } - $final = $goal->get_streak()['max_streak']; + $final = $goal->get_streak(); Settings::set( [ 'badges', 'personal_record_content' ], [ @@ -414,7 +414,7 @@ private function register_badges() { ] ); - return $goal->get_streak()['max_streak']; + return $goal->get_streak(); }, ] ); diff --git a/views/admin-page.php b/views/admin-page.php index 5de50719a..bf64d7e22 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -29,10 +29,10 @@ [ [ 'activity-scores', + 'personal-record-content', 'plugins', 'badge-content', 'badge-streak', - 'personal-record-content', ], [ 'latest-badge', diff --git a/views/widgets/personal-record-content.php b/views/widgets/personal-record-content.php index f7f8bc332..6185466b6 100644 --- a/views/widgets/personal-record-content.php +++ b/views/widgets/personal-record-content.php @@ -9,10 +9,45 @@ $prpl_personal_record_content = \progress_planner()->get_badges()->get_badge_progress( 'personal_record_content' ); -echo '

'; -printf( - /* translators: %s: The number of weeks. */ - esc_html__( 'Personal record: %s weeks of writing content', 'progress-planner' ), - esc_html( $prpl_personal_record_content ) -); -echo '

'; +?> +
+
+ + + + + + +
+
+

+ + + + + + + +

+
+
From 10d24eb635eb8da124ea0dd8ce130cb52b4437b2 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 15 Mar 2024 11:01:09 +0200 Subject: [PATCH 192/490] Add classes to columns --- assets/css/admin.css | 9 ++++++++- views/admin-page.php | 19 +++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/assets/css/admin.css b/assets/css/admin.css index 8dbdf42ee..4488def5f 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -227,6 +227,13 @@ line-height: 2; } +/*------------------------------------*\ + Activity scores +\*------------------------------------*/ +.prpl-widget-wrapper.prpl-activity-scores .prpl-graph-wrapper { + max-height: 300px; +} + /*------------------------------------*\ Badges progress widget. \*------------------------------------*/ @@ -344,7 +351,7 @@ } /*------------------------------------*\ - Personal record widget. + Personal record widget. \*------------------------------------*/ .prpl-widget-wrapper.prpl-personal-record-content .counter-big-wrapper { background-color: var(--prpl-background-green); diff --git a/views/admin-page.php b/views/admin-page.php index bf64d7e22..22a9c9558 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -16,8 +16,8 @@ [ + 'first' => [ 'website-activity-score', 'published-content-density', 'published-content', @@ -26,15 +26,15 @@ 'published-words', ], ], - [ - [ + 'secondary' => [ + 'first' => [ 'activity-scores', 'personal-record-content', 'plugins', 'badge-content', 'badge-streak', ], - [ + 'second' => [ 'latest-badge', 'badges-progress', '__filter-numbers', @@ -43,12 +43,11 @@ ]; ?> -
- -
- -
+ $prpl_column_main ) : ?> +
+ $prpl_column ) : ?> +
From b8cf888736053c95f493511a8407dce63bcb889a Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 15 Mar 2024 11:28:26 +0200 Subject: [PATCH 193/490] styling & layout tweaks --- assets/css/admin.css | 6 ++++++ views/widgets/personal-record-content.php | 2 +- views/widgets/plugins.php | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/assets/css/admin.css b/assets/css/admin.css index 4488def5f..0203452e8 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -128,6 +128,10 @@ grid-gap: var(--prpl-padding); } +.two-col.narrow { + grid-template-columns: repeat(auto-fit, minmax(calc(var(--prpl-column-min-width) / 2), 1fr)); +} + /*------------------------------------*\ Generic styles for individual widgets. \*------------------------------------*/ @@ -149,6 +153,8 @@ display: flex; flex-direction: column; align-items: center; + text-align: center; + align-content: center; } .prpl-wrap .counter-big-number { diff --git a/views/widgets/personal-record-content.php b/views/widgets/personal-record-content.php index 6185466b6..3ece70bf7 100644 --- a/views/widgets/personal-record-content.php +++ b/views/widgets/personal-record-content.php @@ -10,7 +10,7 @@ $prpl_personal_record_content = \progress_planner()->get_badges()->get_badge_progress( 'personal_record_content' ); ?> -
+
diff --git a/views/widgets/plugins.php b/views/widgets/plugins.php index 6d0f7e6e6..45579e18e 100644 --- a/views/widgets/plugins.php +++ b/views/widgets/plugins.php @@ -13,7 +13,7 @@ $prpl_pending_plugin_updates = wp_get_update_data()['counts']['plugins']; ?> -
+
From 144e51d5681f39e9411259c52439b2c1d5ec2e76 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 15 Mar 2024 12:24:23 +0200 Subject: [PATCH 194/490] Experiment with chart.css --- includes/class-chart.php | 67 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 3 deletions(-) diff --git a/includes/class-chart.php b/includes/class-chart.php index 7242d4190..c1273dc79 100644 --- a/includes/class-chart.php +++ b/includes/class-chart.php @@ -211,7 +211,8 @@ public function the_chart( $args = [] ) { } $data['datasets'] = $datasets; - $this->render_chart( + // Render the chart. + $this->render_chart_js( md5( wp_json_encode( $args ) ) . wp_rand( 0, 1000 ), $args['chart_params']['type'], $data, @@ -220,7 +221,7 @@ public function the_chart( $args = [] ) { } /** - * Render the chart. + * Render the chart using Chart.js. * * @param string $id The ID of the chart. * @param string $type The type of chart. @@ -229,7 +230,7 @@ public function the_chart( $args = [] ) { * * @return void */ - public function render_chart( $id, $type, $data, $options = [] ) { + public function render_chart_js( $id, $type, $data, $options = [] ) { $id = 'progress-planner-chart-' . $id; ?> @@ -245,4 +246,64 @@ public function render_chart( $id, $type, $data, $options = [] ) { '; + $css_loaded = true; + ?> + + + + + + + + + + + + + + $value ) : ?> + + + + + + + + +
+ +
+ Date: Fri, 15 Mar 2024 12:47:54 +0200 Subject: [PATCH 195/490] CS --- includes/class-chart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-chart.php b/includes/class-chart.php index c1273dc79..93aeec9d3 100644 --- a/includes/class-chart.php +++ b/includes/class-chart.php @@ -258,7 +258,7 @@ public function render_chart_js( $id, $type, $data, $options = [] ) { * @return void */ public function render_chart_css( $id, $type, $data, $options = [] ) { - $id = 'progress-planner-chart-' . $id; + $id = 'progress-planner-chart-' . $id; static $css_loaded = false; if ( ! $css_loaded ) { echo ''; From 1fc6df6d9eafd35ed4cd63b0aef3c0261e0e9051 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 15 Mar 2024 12:49:17 +0200 Subject: [PATCH 196/490] Add checklist in activity-score widget --- views/widgets/website-activity-score.php | 45 ++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/views/widgets/website-activity-score.php b/views/widgets/website-activity-score.php index 6286542ec..2858b25e0 100644 --- a/views/widgets/website-activity-score.php +++ b/views/widgets/website-activity-score.php @@ -41,6 +41,40 @@ $prpl_score = floor( $prpl_score ); +$prpl_checklist = [ + [ + 'label' => esc_html__( 'Publish or update content', 'progress-planner' ), + 'callback' => function () { + $events = \progress_planner()->get_query()->query_activities( + [ + 'start_date' => new \DateTime( '-7 days' ), + 'end_date' => new \DateTime(), + 'category' => 'content', + ] + ); + return count( $events ) > 0; + }, + ], + [ + 'label' => esc_html__( 'Update plugins', 'progress-planner' ), + 'callback' => function () { + return ! wp_get_update_data()['counts']['plugins']; + }, + ], + [ + 'label' => esc_html__( 'Update themes', 'progress-planner' ), + 'callback' => function () { + return ! wp_get_update_data()['counts']['themes']; + }, + ], + [ + 'label' => esc_html__( 'Update WordPress', 'progress-planner' ), + 'callback' => function () { + return ! wp_get_update_data()['counts']['wordpress']; + }, + ], +]; + ?>

@@ -63,8 +97,13 @@ class="prpl-activities-gauge"

-

Bla bla bla

-

Bla bla bli

-

Bla bla blo

+
    + +
  • + + +
  • + +
From 4155c73deb2c4ead9f05adc36fb7f2887b850360 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 15 Mar 2024 12:53:36 +0200 Subject: [PATCH 197/490] tweak the activities checklist --- views/widgets/website-activity-score.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/views/widgets/website-activity-score.php b/views/widgets/website-activity-score.php index 2858b25e0..e39b686d0 100644 --- a/views/widgets/website-activity-score.php +++ b/views/widgets/website-activity-score.php @@ -43,13 +43,28 @@ $prpl_checklist = [ [ - 'label' => esc_html__( 'Publish or update content', 'progress-planner' ), + 'label' => esc_html__( 'Publish content', 'progress-planner' ), 'callback' => function () { $events = \progress_planner()->get_query()->query_activities( [ 'start_date' => new \DateTime( '-7 days' ), 'end_date' => new \DateTime(), 'category' => 'content', + 'type' => 'publish', + ] + ); + return count( $events ) > 0; + }, + ], + [ + 'label' => esc_html__( 'Update content', 'progress-planner' ), + 'callback' => function () { + $events = \progress_planner()->get_query()->query_activities( + [ + 'start_date' => new \DateTime( '-7 days' ), + 'end_date' => new \DateTime(), + 'category' => 'content', + 'type' => 'update', ] ); return count( $events ) > 0; From a85464295e98a79f20b516eeee1079d0aa1939ad Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 15 Mar 2024 12:59:47 +0200 Subject: [PATCH 198/490] Fix activity-score gauge --- assets/css/admin.css | 3 ++- views/widgets/website-activity-score.php | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/assets/css/admin.css b/assets/css/admin.css index 0203452e8..3fca998d0 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -219,7 +219,8 @@ padding: var(--prpl-padding); background: var(--prpl-background-orange); border-radius: var(--prpl-border-radius); - aspect-ratio: 1 / 1; + aspect-ratio: 2 / 1; + overflow: hidden; top: 50%; } diff --git a/views/widgets/website-activity-score.php b/views/widgets/website-activity-score.php index e39b686d0..9b3f739d5 100644 --- a/views/widgets/website-activity-score.php +++ b/views/widgets/website-activity-score.php @@ -102,8 +102,8 @@ class="prpl-activities-gauge" style=" --value:; --background: var(--prpl-background-orange); - --max: 360deg; - --start: 180deg; + --max: 180deg; + --start: 270deg; --color:" > From 3513a3982bf18a6b9bdc80949d55c2592dd17163 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 15 Mar 2024 13:38:53 +0200 Subject: [PATCH 199/490] fix typo --- views/widgets/personal-record-content.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/views/widgets/personal-record-content.php b/views/widgets/personal-record-content.php index 3ece70bf7..eefcbacdc 100644 --- a/views/widgets/personal-record-content.php +++ b/views/widgets/personal-record-content.php @@ -33,7 +33,7 @@ From 2a3d69c68a2adb78207455b372872edd1b545c44 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 15 Mar 2024 13:57:58 +0200 Subject: [PATCH 200/490] tweak the website-activity score widget --- views/widgets/website-activity-score.php | 30 ++++++++++++++---------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/views/widgets/website-activity-score.php b/views/widgets/website-activity-score.php index 9b3f739d5..7e9f39de5 100644 --- a/views/widgets/website-activity-score.php +++ b/views/widgets/website-activity-score.php @@ -96,22 +96,26 @@
-
-
- - - +
+
+
+ + + +
+
+
  • From 71645a25ba54d8b70a23ba5226169b9202c810cd Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 15 Mar 2024 14:32:38 +0200 Subject: [PATCH 201/490] Add a "what's new" widget --- assets/css/admin.css | 15 +++++++++++++++ includes/class-base.php | 26 ++++++++++++++++++++++++++ views/admin-page.php | 1 + views/widgets/whats-new.php | 29 +++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 views/widgets/whats-new.php diff --git a/assets/css/admin.css b/assets/css/admin.css index 3fca998d0..2c5a4b0a4 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -363,3 +363,18 @@ .prpl-widget-wrapper.prpl-personal-record-content .counter-big-wrapper { background-color: var(--prpl-background-green); } + +/*------------------------------------*\ + What's new widget. +\*------------------------------------*/ +.prpl-widget-wrapper.prpl-whats-new li > a { + color: var(--prpl-color-gray-6); + text-decoration: none; +} + +.prpl-widget-wrapper.prpl-whats-new li > a:active, +.prpl-widget-wrapper.prpl-whats-new li > a:focus, +.prpl-widget-wrapper.prpl-whats-new li > a:hover, +.prpl-widget-wrapper.prpl-whats-new li > a > h3 { + text-decoration: underline; +} diff --git a/includes/class-base.php b/includes/class-base.php index 41320c48d..9178aad81 100644 --- a/includes/class-base.php +++ b/includes/class-base.php @@ -26,6 +26,13 @@ class Base { */ private static $instance; + /** + * The remote server ROOT URL. + * + * @var string + */ + const REMOTE_SERVER_ROOT_URL = 'https://joost.blog'; + /** * Get the single instance of this class. * @@ -82,6 +89,25 @@ public static function get_activation_date() { return \DateTime::createFromFormat( 'Y-m-d', $activation_date ); } + /** + * Get the feed from the blog. + * + * @return array + */ + public function get_blog_feed() { + $feed = get_transient( 'prpl_blog_feed' ); + if ( false === $feed ) { + // Get the feed using the REST API. + $response = wp_remote_get( self::REMOTE_SERVER_ROOT_URL . '/wp-json/wp/v2/posts/?per_page=3' ); + if ( is_wp_error( $response ) ) { + return []; + } + $feed = json_decode( wp_remote_retrieve_body( $response ), true ); + set_transient( 'prpl_blog_feed', $feed, 1 * DAY_IN_SECONDS ); + } + return $feed; + } + /** * THIS SHOULD BE DELETED. * WE ONLY HAVE IT HERE TO EXPERIMENT WITH THE NUMBERS diff --git a/views/admin-page.php b/views/admin-page.php index 22a9c9558..1ad5928d9 100644 --- a/views/admin-page.php +++ b/views/admin-page.php @@ -37,6 +37,7 @@ 'second' => [ 'latest-badge', 'badges-progress', + 'whats-new', '__filter-numbers', ], ], diff --git a/views/widgets/whats-new.php b/views/widgets/whats-new.php new file mode 100644 index 000000000..f83e5eab7 --- /dev/null +++ b/views/widgets/whats-new.php @@ -0,0 +1,29 @@ +get_blog_feed(); +?> +

    + +

    + + + From d7bd9dd7c73661dbaa1cf5fc05c82a23e9d726ae Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 19 Mar 2024 09:23:18 +0200 Subject: [PATCH 202/490] CSS tweaks for badges --- assets/css/admin.css | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/assets/css/admin.css b/assets/css/admin.css index 2c5a4b0a4..aa0131dfd 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -249,10 +249,9 @@ } .prpl-widget-wrapper.prpl-badges-progress .progress-wrapper { - display: flex; + display: grid; + grid-template-columns: 1fr 1fr 1fr; gap: calc(var(--prpl-gap) / 2); - justify-content: center; - flex-wrap: wrap; } .prpl-widget-wrapper.prpl-badges-progress .progress-wrapper .prpl-badge { @@ -261,10 +260,7 @@ align-items: center; justify-content: space-between; flex-wrap: wrap; -} - -.prpl-widget-wrapper.prpl-badges-progress .progress-wrapper .prpl-badge > svg { - width: 100px; + min-width: 0; } .prpl-widget-wrapper.prpl-badges-progress .progress-wrapper { From c87cb3808610fea599424bdc18e7aa09afe10afe Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 19 Mar 2024 09:23:53 +0200 Subject: [PATCH 203/490] Remove chart.css experiment --- includes/class-chart.php | 60 ---------------------------------------- 1 file changed, 60 deletions(-) diff --git a/includes/class-chart.php b/includes/class-chart.php index 93aeec9d3..be059023f 100644 --- a/includes/class-chart.php +++ b/includes/class-chart.php @@ -246,64 +246,4 @@ public function render_chart_js( $id, $type, $data, $options = [] ) { '; - $css_loaded = true; - ?> - - - - - - - - - - - - - - $value ) : ?> - - - - - - - - -
    - -
    - Date: Tue, 19 Mar 2024 09:29:58 +0200 Subject: [PATCH 204/490] Use a local copy of chart.js --- assets/js/chart.min.js | 20 ++++++++++++++++++++ includes/admin/class-page.php | 3 +-- 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 assets/js/chart.min.js diff --git a/assets/js/chart.min.js b/assets/js/chart.min.js new file mode 100644 index 000000000..79f59d7c7 --- /dev/null +++ b/assets/js/chart.min.js @@ -0,0 +1,20 @@ +/** + * Skipped minification because the original files appears to be already minified. + * Original file: /npm/chart.js@4.4.2/dist/chart.umd.js + * + * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files + */ +/*! + * Chart.js v4.4.2 + * https://www.chartjs.org + * (c) 2024 Chart.js Contributors + * Released under the MIT License + */ +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).Chart=e()}(this,(function(){"use strict";var t=Object.freeze({__proto__:null,get Colors(){return Go},get Decimation(){return Qo},get Filler(){return ma},get Legend(){return ya},get SubTitle(){return ka},get Title(){return Ma},get Tooltip(){return Ba}});function e(){}const i=(()=>{let t=0;return()=>t++})();function s(t){return null==t}function n(t){if(Array.isArray&&Array.isArray(t))return!0;const e=Object.prototype.toString.call(t);return"[object"===e.slice(0,7)&&"Array]"===e.slice(-6)}function o(t){return null!==t&&"[object Object]"===Object.prototype.toString.call(t)}function a(t){return("number"==typeof t||t instanceof Number)&&isFinite(+t)}function r(t,e){return a(t)?t:e}function l(t,e){return void 0===t?e:t}const h=(t,e)=>"string"==typeof t&&t.endsWith("%")?parseFloat(t)/100:+t/e,c=(t,e)=>"string"==typeof t&&t.endsWith("%")?parseFloat(t)/100*e:+t;function d(t,e,i){if(t&&"function"==typeof t.call)return t.apply(i,e)}function u(t,e,i,s){let a,r,l;if(n(t))if(r=t.length,s)for(a=r-1;a>=0;a--)e.call(i,t[a],a);else for(a=0;at,x:t=>t.x,y:t=>t.y};function v(t){const e=t.split("."),i=[];let s="";for(const t of e)s+=t,s.endsWith("\\")?s=s.slice(0,-1)+".":(i.push(s),s="");return i}function M(t,e){const i=y[e]||(y[e]=function(t){const e=v(t);return t=>{for(const i of e){if(""===i)break;t=t&&t[i]}return t}}(e));return i(t)}function w(t){return t.charAt(0).toUpperCase()+t.slice(1)}const k=t=>void 0!==t,S=t=>"function"==typeof t,P=(t,e)=>{if(t.size!==e.size)return!1;for(const i of t)if(!e.has(i))return!1;return!0};function D(t){return"mouseup"===t.type||"click"===t.type||"contextmenu"===t.type}const C=Math.PI,O=2*C,A=O+C,T=Number.POSITIVE_INFINITY,L=C/180,E=C/2,R=C/4,I=2*C/3,z=Math.log10,F=Math.sign;function V(t,e,i){return Math.abs(t-e)t-e)).pop(),e}function N(t){return!isNaN(parseFloat(t))&&isFinite(t)}function H(t,e){const i=Math.round(t);return i-e<=t&&i+e>=t}function j(t,e,i){let s,n,o;for(s=0,n=t.length;sl&&h=Math.min(e,i)-s&&t<=Math.max(e,i)+s}function et(t,e,i){i=i||(i=>t[i]1;)s=o+n>>1,i(s)?o=s:n=s;return{lo:o,hi:n}}const it=(t,e,i,s)=>et(t,i,s?s=>{const n=t[s][e];return nt[s][e]et(t,i,(s=>t[s][e]>=i));function nt(t,e,i){let s=0,n=t.length;for(;ss&&t[n-1]>i;)n--;return s>0||n{const i="_onData"+w(e),s=t[e];Object.defineProperty(t,e,{configurable:!0,enumerable:!1,value(...e){const n=s.apply(this,e);return t._chartjs.listeners.forEach((t=>{"function"==typeof t[i]&&t[i](...e)})),n}})})))}function rt(t,e){const i=t._chartjs;if(!i)return;const s=i.listeners,n=s.indexOf(e);-1!==n&&s.splice(n,1),s.length>0||(ot.forEach((e=>{delete t[e]})),delete t._chartjs)}function lt(t){const e=new Set(t);return e.size===t.length?t:Array.from(e)}const ht="undefined"==typeof window?function(t){return t()}:window.requestAnimationFrame;function ct(t,e){let i=[],s=!1;return function(...n){i=n,s||(s=!0,ht.call(window,(()=>{s=!1,t.apply(e,i)})))}}function dt(t,e){let i;return function(...s){return e?(clearTimeout(i),i=setTimeout(t,e,s)):t.apply(this,s),e}}const ut=t=>"start"===t?"left":"end"===t?"right":"center",ft=(t,e,i)=>"start"===t?e:"end"===t?i:(e+i)/2,gt=(t,e,i,s)=>t===(s?"left":"right")?i:"center"===t?(e+i)/2:e;function pt(t,e,i){const s=e.length;let n=0,o=s;if(t._sorted){const{iScale:a,_parsed:r}=t,l=a.axis,{min:h,max:c,minDefined:d,maxDefined:u}=a.getUserBounds();d&&(n=J(Math.min(it(r,l,h).lo,i?s:it(e,l,a.getPixelForValue(h)).lo),0,s-1)),o=u?J(Math.max(it(r,a.axis,c,!0).hi+1,i?0:it(e,l,a.getPixelForValue(c),!0).hi+1),n,s)-n:s-n}return{start:n,count:o}}function mt(t){const{xScale:e,yScale:i,_scaleRanges:s}=t,n={xmin:e.min,xmax:e.max,ymin:i.min,ymax:i.max};if(!s)return t._scaleRanges=n,!0;const o=s.xmin!==e.min||s.xmax!==e.max||s.ymin!==i.min||s.ymax!==i.max;return Object.assign(s,n),o}class bt{constructor(){this._request=null,this._charts=new Map,this._running=!1,this._lastDate=void 0}_notify(t,e,i,s){const n=e.listeners[s],o=e.duration;n.forEach((s=>s({chart:t,initial:e.initial,numSteps:o,currentStep:Math.min(i-e.start,o)})))}_refresh(){this._request||(this._running=!0,this._request=ht.call(window,(()=>{this._update(),this._request=null,this._running&&this._refresh()})))}_update(t=Date.now()){let e=0;this._charts.forEach(((i,s)=>{if(!i.running||!i.items.length)return;const n=i.items;let o,a=n.length-1,r=!1;for(;a>=0;--a)o=n[a],o._active?(o._total>i.duration&&(i.duration=o._total),o.tick(t),r=!0):(n[a]=n[n.length-1],n.pop());r&&(s.draw(),this._notify(s,i,t,"progress")),n.length||(i.running=!1,this._notify(s,i,t,"complete"),i.initial=!1),e+=n.length})),this._lastDate=t,0===e&&(this._running=!1)}_getAnims(t){const e=this._charts;let i=e.get(t);return i||(i={running:!1,initial:!0,items:[],listeners:{complete:[],progress:[]}},e.set(t,i)),i}listen(t,e,i){this._getAnims(t).listeners[e].push(i)}add(t,e){e&&e.length&&this._getAnims(t).items.push(...e)}has(t){return this._getAnims(t).items.length>0}start(t){const e=this._charts.get(t);e&&(e.running=!0,e.start=Date.now(),e.duration=e.items.reduce(((t,e)=>Math.max(t,e._duration)),0),this._refresh())}running(t){if(!this._running)return!1;const e=this._charts.get(t);return!!(e&&e.running&&e.items.length)}stop(t){const e=this._charts.get(t);if(!e||!e.items.length)return;const i=e.items;let s=i.length-1;for(;s>=0;--s)i[s].cancel();e.items=[],this._notify(t,e,Date.now(),"complete")}remove(t){return this._charts.delete(t)}}var xt=new bt; +/*! + * @kurkle/color v0.3.2 + * https://github.com/kurkle/color#readme + * (c) 2023 Jukka Kurkela + * Released under the MIT License + */function _t(t){return t+.5|0}const yt=(t,e,i)=>Math.max(Math.min(t,i),e);function vt(t){return yt(_t(2.55*t),0,255)}function Mt(t){return yt(_t(255*t),0,255)}function wt(t){return yt(_t(t/2.55)/100,0,1)}function kt(t){return yt(_t(100*t),0,100)}const St={0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,A:10,B:11,C:12,D:13,E:14,F:15,a:10,b:11,c:12,d:13,e:14,f:15},Pt=[..."0123456789ABCDEF"],Dt=t=>Pt[15&t],Ct=t=>Pt[(240&t)>>4]+Pt[15&t],Ot=t=>(240&t)>>4==(15&t);function At(t){var e=(t=>Ot(t.r)&&Ot(t.g)&&Ot(t.b)&&Ot(t.a))(t)?Dt:Ct;return t?"#"+e(t.r)+e(t.g)+e(t.b)+((t,e)=>t<255?e(t):"")(t.a,e):void 0}const Tt=/^(hsla?|hwb|hsv)\(\s*([-+.e\d]+)(?:deg)?[\s,]+([-+.e\d]+)%[\s,]+([-+.e\d]+)%(?:[\s,]+([-+.e\d]+)(%)?)?\s*\)$/;function Lt(t,e,i){const s=e*Math.min(i,1-i),n=(e,n=(e+t/30)%12)=>i-s*Math.max(Math.min(n-3,9-n,1),-1);return[n(0),n(8),n(4)]}function Et(t,e,i){const s=(s,n=(s+t/60)%6)=>i-i*e*Math.max(Math.min(n,4-n,1),0);return[s(5),s(3),s(1)]}function Rt(t,e,i){const s=Lt(t,1,.5);let n;for(e+i>1&&(n=1/(e+i),e*=n,i*=n),n=0;n<3;n++)s[n]*=1-e-i,s[n]+=e;return s}function It(t){const e=t.r/255,i=t.g/255,s=t.b/255,n=Math.max(e,i,s),o=Math.min(e,i,s),a=(n+o)/2;let r,l,h;return n!==o&&(h=n-o,l=a>.5?h/(2-n-o):h/(n+o),r=function(t,e,i,s,n){return t===n?(e-i)/s+(e>16&255,o>>8&255,255&o]}return t}(),Ht.transparent=[0,0,0,0]);const e=Ht[t.toLowerCase()];return e&&{r:e[0],g:e[1],b:e[2],a:4===e.length?e[3]:255}}const $t=/^rgba?\(\s*([-+.\d]+)(%)?[\s,]+([-+.e\d]+)(%)?[\s,]+([-+.e\d]+)(%)?(?:[\s,/]+([-+.e\d]+)(%)?)?\s*\)$/;const Yt=t=>t<=.0031308?12.92*t:1.055*Math.pow(t,1/2.4)-.055,Ut=t=>t<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4);function Xt(t,e,i){if(t){let s=It(t);s[e]=Math.max(0,Math.min(s[e]+s[e]*i,0===e?360:1)),s=Ft(s),t.r=s[0],t.g=s[1],t.b=s[2]}}function qt(t,e){return t?Object.assign(e||{},t):t}function Kt(t){var e={r:0,g:0,b:0,a:255};return Array.isArray(t)?t.length>=3&&(e={r:t[0],g:t[1],b:t[2],a:255},t.length>3&&(e.a=Mt(t[3]))):(e=qt(t,{r:0,g:0,b:0,a:1})).a=Mt(e.a),e}function Gt(t){return"r"===t.charAt(0)?function(t){const e=$t.exec(t);let i,s,n,o=255;if(e){if(e[7]!==i){const t=+e[7];o=e[8]?vt(t):yt(255*t,0,255)}return i=+e[1],s=+e[3],n=+e[5],i=255&(e[2]?vt(i):yt(i,0,255)),s=255&(e[4]?vt(s):yt(s,0,255)),n=255&(e[6]?vt(n):yt(n,0,255)),{r:i,g:s,b:n,a:o}}}(t):Bt(t)}class Zt{constructor(t){if(t instanceof Zt)return t;const e=typeof t;let i;var s,n,o;"object"===e?i=Kt(t):"string"===e&&(o=(s=t).length,"#"===s[0]&&(4===o||5===o?n={r:255&17*St[s[1]],g:255&17*St[s[2]],b:255&17*St[s[3]],a:5===o?17*St[s[4]]:255}:7!==o&&9!==o||(n={r:St[s[1]]<<4|St[s[2]],g:St[s[3]]<<4|St[s[4]],b:St[s[5]]<<4|St[s[6]],a:9===o?St[s[7]]<<4|St[s[8]]:255})),i=n||jt(t)||Gt(t)),this._rgb=i,this._valid=!!i}get valid(){return this._valid}get rgb(){var t=qt(this._rgb);return t&&(t.a=wt(t.a)),t}set rgb(t){this._rgb=Kt(t)}rgbString(){return this._valid?(t=this._rgb)&&(t.a<255?`rgba(${t.r}, ${t.g}, ${t.b}, ${wt(t.a)})`:`rgb(${t.r}, ${t.g}, ${t.b})`):void 0;var t}hexString(){return this._valid?At(this._rgb):void 0}hslString(){return this._valid?function(t){if(!t)return;const e=It(t),i=e[0],s=kt(e[1]),n=kt(e[2]);return t.a<255?`hsla(${i}, ${s}%, ${n}%, ${wt(t.a)})`:`hsl(${i}, ${s}%, ${n}%)`}(this._rgb):void 0}mix(t,e){if(t){const i=this.rgb,s=t.rgb;let n;const o=e===n?.5:e,a=2*o-1,r=i.a-s.a,l=((a*r==-1?a:(a+r)/(1+a*r))+1)/2;n=1-l,i.r=255&l*i.r+n*s.r+.5,i.g=255&l*i.g+n*s.g+.5,i.b=255&l*i.b+n*s.b+.5,i.a=o*i.a+(1-o)*s.a,this.rgb=i}return this}interpolate(t,e){return t&&(this._rgb=function(t,e,i){const s=Ut(wt(t.r)),n=Ut(wt(t.g)),o=Ut(wt(t.b));return{r:Mt(Yt(s+i*(Ut(wt(e.r))-s))),g:Mt(Yt(n+i*(Ut(wt(e.g))-n))),b:Mt(Yt(o+i*(Ut(wt(e.b))-o))),a:t.a+i*(e.a-t.a)}}(this._rgb,t._rgb,e)),this}clone(){return new Zt(this.rgb)}alpha(t){return this._rgb.a=Mt(t),this}clearer(t){return this._rgb.a*=1-t,this}greyscale(){const t=this._rgb,e=_t(.3*t.r+.59*t.g+.11*t.b);return t.r=t.g=t.b=e,this}opaquer(t){return this._rgb.a*=1+t,this}negate(){const t=this._rgb;return t.r=255-t.r,t.g=255-t.g,t.b=255-t.b,this}lighten(t){return Xt(this._rgb,2,t),this}darken(t){return Xt(this._rgb,2,-t),this}saturate(t){return Xt(this._rgb,1,t),this}desaturate(t){return Xt(this._rgb,1,-t),this}rotate(t){return function(t,e){var i=It(t);i[0]=Vt(i[0]+e),i=Ft(i),t.r=i[0],t.g=i[1],t.b=i[2]}(this._rgb,t),this}}function Jt(t){if(t&&"object"==typeof t){const e=t.toString();return"[object CanvasPattern]"===e||"[object CanvasGradient]"===e}return!1}function Qt(t){return Jt(t)?t:new Zt(t)}function te(t){return Jt(t)?t:new Zt(t).saturate(.5).darken(.1).hexString()}const ee=["x","y","borderWidth","radius","tension"],ie=["color","borderColor","backgroundColor"];const se=new Map;function ne(t,e,i){return function(t,e){e=e||{};const i=t+JSON.stringify(e);let s=se.get(i);return s||(s=new Intl.NumberFormat(t,e),se.set(i,s)),s}(e,i).format(t)}const oe={values:t=>n(t)?t:""+t,numeric(t,e,i){if(0===t)return"0";const s=this.chart.options.locale;let n,o=t;if(i.length>1){const e=Math.max(Math.abs(i[0].value),Math.abs(i[i.length-1].value));(e<1e-4||e>1e15)&&(n="scientific"),o=function(t,e){let i=e.length>3?e[2].value-e[1].value:e[1].value-e[0].value;Math.abs(i)>=1&&t!==Math.floor(t)&&(i=t-Math.floor(t));return i}(t,i)}const a=z(Math.abs(o)),r=isNaN(a)?1:Math.max(Math.min(-1*Math.floor(a),20),0),l={notation:n,minimumFractionDigits:r,maximumFractionDigits:r};return Object.assign(l,this.options.ticks.format),ne(t,s,l)},logarithmic(t,e,i){if(0===t)return"0";const s=i[e].significand||t/Math.pow(10,Math.floor(z(t)));return[1,2,3,5,10,15].includes(s)||e>.8*i.length?oe.numeric.call(this,t,e,i):""}};var ae={formatters:oe};const re=Object.create(null),le=Object.create(null);function he(t,e){if(!e)return t;const i=e.split(".");for(let e=0,s=i.length;et.chart.platform.getDevicePixelRatio(),this.elements={},this.events=["mousemove","mouseout","click","touchstart","touchmove"],this.font={family:"'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",size:12,style:"normal",lineHeight:1.2,weight:null},this.hover={},this.hoverBackgroundColor=(t,e)=>te(e.backgroundColor),this.hoverBorderColor=(t,e)=>te(e.borderColor),this.hoverColor=(t,e)=>te(e.color),this.indexAxis="x",this.interaction={mode:"nearest",intersect:!0,includeInvisible:!1},this.maintainAspectRatio=!0,this.onHover=null,this.onClick=null,this.parsing=!0,this.plugins={},this.responsive=!0,this.scale=void 0,this.scales={},this.showLine=!0,this.drawActiveElementsOnTop=!0,this.describe(t),this.apply(e)}set(t,e){return ce(this,t,e)}get(t){return he(this,t)}describe(t,e){return ce(le,t,e)}override(t,e){return ce(re,t,e)}route(t,e,i,s){const n=he(this,t),a=he(this,i),r="_"+e;Object.defineProperties(n,{[r]:{value:n[e],writable:!0},[e]:{enumerable:!0,get(){const t=this[r],e=a[s];return o(t)?Object.assign({},e,t):l(t,e)},set(t){this[r]=t}}})}apply(t){t.forEach((t=>t(this)))}}var ue=new de({_scriptable:t=>!t.startsWith("on"),_indexable:t=>"events"!==t,hover:{_fallback:"interaction"},interaction:{_scriptable:!1,_indexable:!1}},[function(t){t.set("animation",{delay:void 0,duration:1e3,easing:"easeOutQuart",fn:void 0,from:void 0,loop:void 0,to:void 0,type:void 0}),t.describe("animation",{_fallback:!1,_indexable:!1,_scriptable:t=>"onProgress"!==t&&"onComplete"!==t&&"fn"!==t}),t.set("animations",{colors:{type:"color",properties:ie},numbers:{type:"number",properties:ee}}),t.describe("animations",{_fallback:"animation"}),t.set("transitions",{active:{animation:{duration:400}},resize:{animation:{duration:0}},show:{animations:{colors:{from:"transparent"},visible:{type:"boolean",duration:0}}},hide:{animations:{colors:{to:"transparent"},visible:{type:"boolean",easing:"linear",fn:t=>0|t}}}})},function(t){t.set("layout",{autoPadding:!0,padding:{top:0,right:0,bottom:0,left:0}})},function(t){t.set("scale",{display:!0,offset:!1,reverse:!1,beginAtZero:!1,bounds:"ticks",clip:!0,grace:0,grid:{display:!0,lineWidth:1,drawOnChartArea:!0,drawTicks:!0,tickLength:8,tickWidth:(t,e)=>e.lineWidth,tickColor:(t,e)=>e.color,offset:!1},border:{display:!0,dash:[],dashOffset:0,width:1},title:{display:!1,text:"",padding:{top:4,bottom:4}},ticks:{minRotation:0,maxRotation:50,mirror:!1,textStrokeWidth:0,textStrokeColor:"",padding:3,display:!0,autoSkip:!0,autoSkipPadding:3,labelOffset:0,callback:ae.formatters.values,minor:{},major:{},align:"center",crossAlign:"near",showLabelBackdrop:!1,backdropColor:"rgba(255, 255, 255, 0.75)",backdropPadding:2}}),t.route("scale.ticks","color","","color"),t.route("scale.grid","color","","borderColor"),t.route("scale.border","color","","borderColor"),t.route("scale.title","color","","color"),t.describe("scale",{_fallback:!1,_scriptable:t=>!t.startsWith("before")&&!t.startsWith("after")&&"callback"!==t&&"parser"!==t,_indexable:t=>"borderDash"!==t&&"tickBorderDash"!==t&&"dash"!==t}),t.describe("scales",{_fallback:"scale"}),t.describe("scale.ticks",{_scriptable:t=>"backdropPadding"!==t&&"callback"!==t,_indexable:t=>"backdropPadding"!==t})}]);function fe(){return"undefined"!=typeof window&&"undefined"!=typeof document}function ge(t){let e=t.parentNode;return e&&"[object ShadowRoot]"===e.toString()&&(e=e.host),e}function pe(t,e,i){let s;return"string"==typeof t?(s=parseInt(t,10),-1!==t.indexOf("%")&&(s=s/100*e.parentNode[i])):s=t,s}const me=t=>t.ownerDocument.defaultView.getComputedStyle(t,null);function be(t,e){return me(t).getPropertyValue(e)}const xe=["top","right","bottom","left"];function _e(t,e,i){const s={};i=i?"-"+i:"";for(let n=0;n<4;n++){const o=xe[n];s[o]=parseFloat(t[e+"-"+o+i])||0}return s.width=s.left+s.right,s.height=s.top+s.bottom,s}const ye=(t,e,i)=>(t>0||e>0)&&(!i||!i.shadowRoot);function ve(t,e){if("native"in t)return t;const{canvas:i,currentDevicePixelRatio:s}=e,n=me(i),o="border-box"===n.boxSizing,a=_e(n,"padding"),r=_e(n,"border","width"),{x:l,y:h,box:c}=function(t,e){const i=t.touches,s=i&&i.length?i[0]:t,{offsetX:n,offsetY:o}=s;let a,r,l=!1;if(ye(n,o,t.target))a=n,r=o;else{const t=e.getBoundingClientRect();a=s.clientX-t.left,r=s.clientY-t.top,l=!0}return{x:a,y:r,box:l}}(t,i),d=a.left+(c&&r.left),u=a.top+(c&&r.top);let{width:f,height:g}=e;return o&&(f-=a.width+r.width,g-=a.height+r.height),{x:Math.round((l-d)/f*i.width/s),y:Math.round((h-u)/g*i.height/s)}}const Me=t=>Math.round(10*t)/10;function we(t,e,i,s){const n=me(t),o=_e(n,"margin"),a=pe(n.maxWidth,t,"clientWidth")||T,r=pe(n.maxHeight,t,"clientHeight")||T,l=function(t,e,i){let s,n;if(void 0===e||void 0===i){const o=ge(t);if(o){const t=o.getBoundingClientRect(),a=me(o),r=_e(a,"border","width"),l=_e(a,"padding");e=t.width-l.width-r.width,i=t.height-l.height-r.height,s=pe(a.maxWidth,o,"clientWidth"),n=pe(a.maxHeight,o,"clientHeight")}else e=t.clientWidth,i=t.clientHeight}return{width:e,height:i,maxWidth:s||T,maxHeight:n||T}}(t,e,i);let{width:h,height:c}=l;if("content-box"===n.boxSizing){const t=_e(n,"border","width"),e=_e(n,"padding");h-=e.width+t.width,c-=e.height+t.height}h=Math.max(0,h-o.width),c=Math.max(0,s?h/s:c-o.height),h=Me(Math.min(h,a,l.maxWidth)),c=Me(Math.min(c,r,l.maxHeight)),h&&!c&&(c=Me(h/2));return(void 0!==e||void 0!==i)&&s&&l.height&&c>l.height&&(c=l.height,h=Me(Math.floor(c*s))),{width:h,height:c}}function ke(t,e,i){const s=e||1,n=Math.floor(t.height*s),o=Math.floor(t.width*s);t.height=Math.floor(t.height),t.width=Math.floor(t.width);const a=t.canvas;return a.style&&(i||!a.style.height&&!a.style.width)&&(a.style.height=`${t.height}px`,a.style.width=`${t.width}px`),(t.currentDevicePixelRatio!==s||a.height!==n||a.width!==o)&&(t.currentDevicePixelRatio=s,a.height=n,a.width=o,t.ctx.setTransform(s,0,0,s,0,0),!0)}const Se=function(){let t=!1;try{const e={get passive(){return t=!0,!1}};fe()&&(window.addEventListener("test",null,e),window.removeEventListener("test",null,e))}catch(t){}return t}();function Pe(t,e){const i=be(t,e),s=i&&i.match(/^(\d+)(\.\d+)?px$/);return s?+s[1]:void 0}function De(t){return!t||s(t.size)||s(t.family)?null:(t.style?t.style+" ":"")+(t.weight?t.weight+" ":"")+t.size+"px "+t.family}function Ce(t,e,i,s,n){let o=e[n];return o||(o=e[n]=t.measureText(n).width,i.push(n)),o>s&&(s=o),s}function Oe(t,e,i,s){let o=(s=s||{}).data=s.data||{},a=s.garbageCollect=s.garbageCollect||[];s.font!==e&&(o=s.data={},a=s.garbageCollect=[],s.font=e),t.save(),t.font=e;let r=0;const l=i.length;let h,c,d,u,f;for(h=0;hi.length){for(h=0;h0&&t.stroke()}}function Re(t,e,i){return i=i||.5,!e||t&&t.x>e.left-i&&t.xe.top-i&&t.y0&&""!==r.strokeColor;let c,d;for(t.save(),t.font=a.string,function(t,e){e.translation&&t.translate(e.translation[0],e.translation[1]),s(e.rotation)||t.rotate(e.rotation),e.color&&(t.fillStyle=e.color),e.textAlign&&(t.textAlign=e.textAlign),e.textBaseline&&(t.textBaseline=e.textBaseline)}(t,r),c=0;ct[0])){const o=i||t;void 0===s&&(s=ti("_fallback",t));const a={[Symbol.toStringTag]:"Object",_cacheable:!0,_scopes:t,_rootScopes:o,_fallback:s,_getTarget:n,override:i=>je([i,...t],e,o,s)};return new Proxy(a,{deleteProperty:(e,i)=>(delete e[i],delete e._keys,delete t[0][i],!0),get:(i,s)=>qe(i,s,(()=>function(t,e,i,s){let n;for(const o of e)if(n=ti(Ue(o,t),i),void 0!==n)return Xe(t,n)?Je(i,s,t,n):n}(s,e,t,i))),getOwnPropertyDescriptor:(t,e)=>Reflect.getOwnPropertyDescriptor(t._scopes[0],e),getPrototypeOf:()=>Reflect.getPrototypeOf(t[0]),has:(t,e)=>ei(t).includes(e),ownKeys:t=>ei(t),set(t,e,i){const s=t._storage||(t._storage=n());return t[e]=s[e]=i,delete t._keys,!0}})}function $e(t,e,i,s){const a={_cacheable:!1,_proxy:t,_context:e,_subProxy:i,_stack:new Set,_descriptors:Ye(t,s),setContext:e=>$e(t,e,i,s),override:n=>$e(t.override(n),e,i,s)};return new Proxy(a,{deleteProperty:(e,i)=>(delete e[i],delete t[i],!0),get:(t,e,i)=>qe(t,e,(()=>function(t,e,i){const{_proxy:s,_context:a,_subProxy:r,_descriptors:l}=t;let h=s[e];S(h)&&l.isScriptable(e)&&(h=function(t,e,i,s){const{_proxy:n,_context:o,_subProxy:a,_stack:r}=i;if(r.has(t))throw new Error("Recursion detected: "+Array.from(r).join("->")+"->"+t);r.add(t);let l=e(o,a||s);r.delete(t),Xe(t,l)&&(l=Je(n._scopes,n,t,l));return l}(e,h,t,i));n(h)&&h.length&&(h=function(t,e,i,s){const{_proxy:n,_context:a,_subProxy:r,_descriptors:l}=i;if(void 0!==a.index&&s(t))return e[a.index%e.length];if(o(e[0])){const i=e,s=n._scopes.filter((t=>t!==i));e=[];for(const o of i){const i=Je(s,n,t,o);e.push($e(i,a,r&&r[t],l))}}return e}(e,h,t,l.isIndexable));Xe(e,h)&&(h=$e(h,a,r&&r[e],l));return h}(t,e,i))),getOwnPropertyDescriptor:(e,i)=>e._descriptors.allKeys?Reflect.has(t,i)?{enumerable:!0,configurable:!0}:void 0:Reflect.getOwnPropertyDescriptor(t,i),getPrototypeOf:()=>Reflect.getPrototypeOf(t),has:(e,i)=>Reflect.has(t,i),ownKeys:()=>Reflect.ownKeys(t),set:(e,i,s)=>(t[i]=s,delete e[i],!0)})}function Ye(t,e={scriptable:!0,indexable:!0}){const{_scriptable:i=e.scriptable,_indexable:s=e.indexable,_allKeys:n=e.allKeys}=t;return{allKeys:n,scriptable:i,indexable:s,isScriptable:S(i)?i:()=>i,isIndexable:S(s)?s:()=>s}}const Ue=(t,e)=>t?t+w(e):e,Xe=(t,e)=>o(e)&&"adapters"!==t&&(null===Object.getPrototypeOf(e)||e.constructor===Object);function qe(t,e,i){if(Object.prototype.hasOwnProperty.call(t,e))return t[e];const s=i();return t[e]=s,s}function Ke(t,e,i){return S(t)?t(e,i):t}const Ge=(t,e)=>!0===t?e:"string"==typeof t?M(e,t):void 0;function Ze(t,e,i,s,n){for(const o of e){const e=Ge(i,o);if(e){t.add(e);const o=Ke(e._fallback,i,n);if(void 0!==o&&o!==i&&o!==s)return o}else if(!1===e&&void 0!==s&&i!==s)return null}return!1}function Je(t,e,i,s){const a=e._rootScopes,r=Ke(e._fallback,i,s),l=[...t,...a],h=new Set;h.add(s);let c=Qe(h,l,i,r||i,s);return null!==c&&((void 0===r||r===i||(c=Qe(h,l,r,c,s),null!==c))&&je(Array.from(h),[""],a,r,(()=>function(t,e,i){const s=t._getTarget();e in s||(s[e]={});const a=s[e];if(n(a)&&o(i))return i;return a||{}}(e,i,s))))}function Qe(t,e,i,s,n){for(;i;)i=Ze(t,e,i,s,n);return i}function ti(t,e){for(const i of e){if(!i)continue;const e=i[t];if(void 0!==e)return e}}function ei(t){let e=t._keys;return e||(e=t._keys=function(t){const e=new Set;for(const i of t)for(const t of Object.keys(i).filter((t=>!t.startsWith("_"))))e.add(t);return Array.from(e)}(t._scopes)),e}function ii(t,e,i,s){const{iScale:n}=t,{key:o="r"}=this._parsing,a=new Array(s);let r,l,h,c;for(r=0,l=s;re"x"===t?"y":"x";function ai(t,e,i,s){const n=t.skip?e:t,o=e,a=i.skip?e:i,r=q(o,n),l=q(a,o);let h=r/(r+l),c=l/(r+l);h=isNaN(h)?0:h,c=isNaN(c)?0:c;const d=s*h,u=s*c;return{previous:{x:o.x-d*(a.x-n.x),y:o.y-d*(a.y-n.y)},next:{x:o.x+u*(a.x-n.x),y:o.y+u*(a.y-n.y)}}}function ri(t,e="x"){const i=oi(e),s=t.length,n=Array(s).fill(0),o=Array(s);let a,r,l,h=ni(t,0);for(a=0;a!t.skip))),"monotone"===e.cubicInterpolationMode)ri(t,n);else{let i=s?t[t.length-1]:t[0];for(o=0,a=t.length;o0===t||1===t,di=(t,e,i)=>-Math.pow(2,10*(t-=1))*Math.sin((t-e)*O/i),ui=(t,e,i)=>Math.pow(2,-10*t)*Math.sin((t-e)*O/i)+1,fi={linear:t=>t,easeInQuad:t=>t*t,easeOutQuad:t=>-t*(t-2),easeInOutQuad:t=>(t/=.5)<1?.5*t*t:-.5*(--t*(t-2)-1),easeInCubic:t=>t*t*t,easeOutCubic:t=>(t-=1)*t*t+1,easeInOutCubic:t=>(t/=.5)<1?.5*t*t*t:.5*((t-=2)*t*t+2),easeInQuart:t=>t*t*t*t,easeOutQuart:t=>-((t-=1)*t*t*t-1),easeInOutQuart:t=>(t/=.5)<1?.5*t*t*t*t:-.5*((t-=2)*t*t*t-2),easeInQuint:t=>t*t*t*t*t,easeOutQuint:t=>(t-=1)*t*t*t*t+1,easeInOutQuint:t=>(t/=.5)<1?.5*t*t*t*t*t:.5*((t-=2)*t*t*t*t+2),easeInSine:t=>1-Math.cos(t*E),easeOutSine:t=>Math.sin(t*E),easeInOutSine:t=>-.5*(Math.cos(C*t)-1),easeInExpo:t=>0===t?0:Math.pow(2,10*(t-1)),easeOutExpo:t=>1===t?1:1-Math.pow(2,-10*t),easeInOutExpo:t=>ci(t)?t:t<.5?.5*Math.pow(2,10*(2*t-1)):.5*(2-Math.pow(2,-10*(2*t-1))),easeInCirc:t=>t>=1?t:-(Math.sqrt(1-t*t)-1),easeOutCirc:t=>Math.sqrt(1-(t-=1)*t),easeInOutCirc:t=>(t/=.5)<1?-.5*(Math.sqrt(1-t*t)-1):.5*(Math.sqrt(1-(t-=2)*t)+1),easeInElastic:t=>ci(t)?t:di(t,.075,.3),easeOutElastic:t=>ci(t)?t:ui(t,.075,.3),easeInOutElastic(t){const e=.1125;return ci(t)?t:t<.5?.5*di(2*t,e,.45):.5+.5*ui(2*t-1,e,.45)},easeInBack(t){const e=1.70158;return t*t*((e+1)*t-e)},easeOutBack(t){const e=1.70158;return(t-=1)*t*((e+1)*t+e)+1},easeInOutBack(t){let e=1.70158;return(t/=.5)<1?t*t*((1+(e*=1.525))*t-e)*.5:.5*((t-=2)*t*((1+(e*=1.525))*t+e)+2)},easeInBounce:t=>1-fi.easeOutBounce(1-t),easeOutBounce(t){const e=7.5625,i=2.75;return t<1/i?e*t*t:t<2/i?e*(t-=1.5/i)*t+.75:t<2.5/i?e*(t-=2.25/i)*t+.9375:e*(t-=2.625/i)*t+.984375},easeInOutBounce:t=>t<.5?.5*fi.easeInBounce(2*t):.5*fi.easeOutBounce(2*t-1)+.5};function gi(t,e,i,s){return{x:t.x+i*(e.x-t.x),y:t.y+i*(e.y-t.y)}}function pi(t,e,i,s){return{x:t.x+i*(e.x-t.x),y:"middle"===s?i<.5?t.y:e.y:"after"===s?i<1?t.y:e.y:i>0?e.y:t.y}}function mi(t,e,i,s){const n={x:t.cp2x,y:t.cp2y},o={x:e.cp1x,y:e.cp1y},a=gi(t,n,i),r=gi(n,o,i),l=gi(o,e,i),h=gi(a,r,i),c=gi(r,l,i);return gi(h,c,i)}const bi=/^(normal|(\d+(?:\.\d+)?)(px|em|%)?)$/,xi=/^(normal|italic|initial|inherit|unset|(oblique( -?[0-9]?[0-9]deg)?))$/;function _i(t,e){const i=(""+t).match(bi);if(!i||"normal"===i[1])return 1.2*e;switch(t=+i[2],i[3]){case"px":return t;case"%":t/=100}return e*t}const yi=t=>+t||0;function vi(t,e){const i={},s=o(e),n=s?Object.keys(e):e,a=o(t)?s?i=>l(t[i],t[e[i]]):e=>t[e]:()=>t;for(const t of n)i[t]=yi(a(t));return i}function Mi(t){return vi(t,{top:"y",right:"x",bottom:"y",left:"x"})}function wi(t){return vi(t,["topLeft","topRight","bottomLeft","bottomRight"])}function ki(t){const e=Mi(t);return e.width=e.left+e.right,e.height=e.top+e.bottom,e}function Si(t,e){t=t||{},e=e||ue.font;let i=l(t.size,e.size);"string"==typeof i&&(i=parseInt(i,10));let s=l(t.style,e.style);s&&!(""+s).match(xi)&&(console.warn('Invalid font style specified: "'+s+'"'),s=void 0);const n={family:l(t.family,e.family),lineHeight:_i(l(t.lineHeight,e.lineHeight),i),size:i,style:s,weight:l(t.weight,e.weight),string:""};return n.string=De(n),n}function Pi(t,e,i,s){let o,a,r,l=!0;for(o=0,a=t.length;oi&&0===t?0:t+e;return{min:a(s,-Math.abs(o)),max:a(n,o)}}function Ci(t,e){return Object.assign(Object.create(t),e)}function Oi(t,e,i){return t?function(t,e){return{x:i=>t+t+e-i,setWidth(t){e=t},textAlign:t=>"center"===t?t:"right"===t?"left":"right",xPlus:(t,e)=>t-e,leftForLtr:(t,e)=>t-e}}(e,i):{x:t=>t,setWidth(t){},textAlign:t=>t,xPlus:(t,e)=>t+e,leftForLtr:(t,e)=>t}}function Ai(t,e){let i,s;"ltr"!==e&&"rtl"!==e||(i=t.canvas.style,s=[i.getPropertyValue("direction"),i.getPropertyPriority("direction")],i.setProperty("direction",e,"important"),t.prevTextDirection=s)}function Ti(t,e){void 0!==e&&(delete t.prevTextDirection,t.canvas.style.setProperty("direction",e[0],e[1]))}function Li(t){return"angle"===t?{between:Z,compare:K,normalize:G}:{between:tt,compare:(t,e)=>t-e,normalize:t=>t}}function Ei({start:t,end:e,count:i,loop:s,style:n}){return{start:t%i,end:e%i,loop:s&&(e-t+1)%i==0,style:n}}function Ri(t,e,i){if(!i)return[t];const{property:s,start:n,end:o}=i,a=e.length,{compare:r,between:l,normalize:h}=Li(s),{start:c,end:d,loop:u,style:f}=function(t,e,i){const{property:s,start:n,end:o}=i,{between:a,normalize:r}=Li(s),l=e.length;let h,c,{start:d,end:u,loop:f}=t;if(f){for(d+=l,u+=l,h=0,c=l;hx||l(n,b,p)&&0!==r(n,b),v=()=>!x||0===r(o,p)||l(o,b,p);for(let t=c,i=c;t<=d;++t)m=e[t%a],m.skip||(p=h(m[s]),p!==b&&(x=l(p,n,o),null===_&&y()&&(_=0===r(p,n)?t:i),null!==_&&v()&&(g.push(Ei({start:_,end:t,loop:u,count:a,style:f})),_=null),i=t,b=p));return null!==_&&g.push(Ei({start:_,end:d,loop:u,count:a,style:f})),g}function Ii(t,e){const i=[],s=t.segments;for(let n=0;nn&&t[o%e].skip;)o--;return o%=e,{start:n,end:o}}(i,n,o,s);if(!0===s)return Fi(t,[{start:a,end:r,loop:o}],i,e);return Fi(t,function(t,e,i,s){const n=t.length,o=[];let a,r=e,l=t[e];for(a=e+1;a<=i;++a){const i=t[a%n];i.skip||i.stop?l.skip||(s=!1,o.push({start:e%n,end:(a-1)%n,loop:s}),e=r=i.stop?a:null):(r=a,l.skip&&(e=a)),l=i}return null!==r&&o.push({start:e%n,end:r%n,loop:s}),o}(i,a,r{t[a](e[i],n)&&(o.push({element:t,datasetIndex:s,index:l}),r=r||t.inRange(e.x,e.y,n))})),s&&!r?[]:o}var Xi={evaluateInteractionItems:Hi,modes:{index(t,e,i,s){const n=ve(e,t),o=i.axis||"x",a=i.includeInvisible||!1,r=i.intersect?ji(t,n,o,s,a):Yi(t,n,o,!1,s,a),l=[];return r.length?(t.getSortedVisibleDatasetMetas().forEach((t=>{const e=r[0].index,i=t.data[e];i&&!i.skip&&l.push({element:i,datasetIndex:t.index,index:e})})),l):[]},dataset(t,e,i,s){const n=ve(e,t),o=i.axis||"xy",a=i.includeInvisible||!1;let r=i.intersect?ji(t,n,o,s,a):Yi(t,n,o,!1,s,a);if(r.length>0){const e=r[0].datasetIndex,i=t.getDatasetMeta(e).data;r=[];for(let t=0;tji(t,ve(e,t),i.axis||"xy",s,i.includeInvisible||!1),nearest(t,e,i,s){const n=ve(e,t),o=i.axis||"xy",a=i.includeInvisible||!1;return Yi(t,n,o,i.intersect,s,a)},x:(t,e,i,s)=>Ui(t,ve(e,t),"x",i.intersect,s),y:(t,e,i,s)=>Ui(t,ve(e,t),"y",i.intersect,s)}};const qi=["left","top","right","bottom"];function Ki(t,e){return t.filter((t=>t.pos===e))}function Gi(t,e){return t.filter((t=>-1===qi.indexOf(t.pos)&&t.box.axis===e))}function Zi(t,e){return t.sort(((t,i)=>{const s=e?i:t,n=e?t:i;return s.weight===n.weight?s.index-n.index:s.weight-n.weight}))}function Ji(t,e){const i=function(t){const e={};for(const i of t){const{stack:t,pos:s,stackWeight:n}=i;if(!t||!qi.includes(s))continue;const o=e[t]||(e[t]={count:0,placed:0,weight:0,size:0});o.count++,o.weight+=n}return e}(t),{vBoxMaxWidth:s,hBoxMaxHeight:n}=e;let o,a,r;for(o=0,a=t.length;o{s[t]=Math.max(e[t],i[t])})),s}return s(t?["left","right"]:["top","bottom"])}function ss(t,e,i,s){const n=[];let o,a,r,l,h,c;for(o=0,a=t.length,h=0;ot.box.fullSize)),!0),s=Zi(Ki(e,"left"),!0),n=Zi(Ki(e,"right")),o=Zi(Ki(e,"top"),!0),a=Zi(Ki(e,"bottom")),r=Gi(e,"x"),l=Gi(e,"y");return{fullSize:i,leftAndTop:s.concat(o),rightAndBottom:n.concat(l).concat(a).concat(r),chartArea:Ki(e,"chartArea"),vertical:s.concat(n).concat(l),horizontal:o.concat(a).concat(r)}}(t.boxes),l=r.vertical,h=r.horizontal;u(t.boxes,(t=>{"function"==typeof t.beforeLayout&&t.beforeLayout()}));const c=l.reduce(((t,e)=>e.box.options&&!1===e.box.options.display?t:t+1),0)||1,d=Object.freeze({outerWidth:e,outerHeight:i,padding:n,availableWidth:o,availableHeight:a,vBoxMaxWidth:o/2/c,hBoxMaxHeight:a/2}),f=Object.assign({},n);ts(f,ki(s));const g=Object.assign({maxPadding:f,w:o,h:a,x:n.left,y:n.top},n),p=Ji(l.concat(h),d);ss(r.fullSize,g,d,p),ss(l,g,d,p),ss(h,g,d,p)&&ss(l,g,d,p),function(t){const e=t.maxPadding;function i(i){const s=Math.max(e[i]-t[i],0);return t[i]+=s,s}t.y+=i("top"),t.x+=i("left"),i("right"),i("bottom")}(g),os(r.leftAndTop,g,d,p),g.x+=g.w,g.y+=g.h,os(r.rightAndBottom,g,d,p),t.chartArea={left:g.left,top:g.top,right:g.left+g.w,bottom:g.top+g.h,height:g.h,width:g.w},u(r.chartArea,(e=>{const i=e.box;Object.assign(i,t.chartArea),i.update(g.w,g.h,{left:0,top:0,right:0,bottom:0})}))}};class rs{acquireContext(t,e){}releaseContext(t){return!1}addEventListener(t,e,i){}removeEventListener(t,e,i){}getDevicePixelRatio(){return 1}getMaximumSize(t,e,i,s){return e=Math.max(0,e||t.width),i=i||t.height,{width:e,height:Math.max(0,s?Math.floor(e/s):i)}}isAttached(t){return!0}updateConfig(t){}}class ls extends rs{acquireContext(t){return t&&t.getContext&&t.getContext("2d")||null}updateConfig(t){t.options.animation=!1}}const hs="$chartjs",cs={touchstart:"mousedown",touchmove:"mousemove",touchend:"mouseup",pointerenter:"mouseenter",pointerdown:"mousedown",pointermove:"mousemove",pointerup:"mouseup",pointerleave:"mouseout",pointerout:"mouseout"},ds=t=>null===t||""===t;const us=!!Se&&{passive:!0};function fs(t,e,i){t&&t.canvas&&t.canvas.removeEventListener(e,i,us)}function gs(t,e){for(const i of t)if(i===e||i.contains(e))return!0}function ps(t,e,i){const s=t.canvas,n=new MutationObserver((t=>{let e=!1;for(const i of t)e=e||gs(i.addedNodes,s),e=e&&!gs(i.removedNodes,s);e&&i()}));return n.observe(document,{childList:!0,subtree:!0}),n}function ms(t,e,i){const s=t.canvas,n=new MutationObserver((t=>{let e=!1;for(const i of t)e=e||gs(i.removedNodes,s),e=e&&!gs(i.addedNodes,s);e&&i()}));return n.observe(document,{childList:!0,subtree:!0}),n}const bs=new Map;let xs=0;function _s(){const t=window.devicePixelRatio;t!==xs&&(xs=t,bs.forEach(((e,i)=>{i.currentDevicePixelRatio!==t&&e()})))}function ys(t,e,i){const s=t.canvas,n=s&&ge(s);if(!n)return;const o=ct(((t,e)=>{const s=n.clientWidth;i(t,e),s{const e=t[0],i=e.contentRect.width,s=e.contentRect.height;0===i&&0===s||o(i,s)}));return a.observe(n),function(t,e){bs.size||window.addEventListener("resize",_s),bs.set(t,e)}(t,o),a}function vs(t,e,i){i&&i.disconnect(),"resize"===e&&function(t){bs.delete(t),bs.size||window.removeEventListener("resize",_s)}(t)}function Ms(t,e,i){const s=t.canvas,n=ct((e=>{null!==t.ctx&&i(function(t,e){const i=cs[t.type]||t.type,{x:s,y:n}=ve(t,e);return{type:i,chart:e,native:t,x:void 0!==s?s:null,y:void 0!==n?n:null}}(e,t))}),t);return function(t,e,i){t&&t.addEventListener(e,i,us)}(s,e,n),n}class ws extends rs{acquireContext(t,e){const i=t&&t.getContext&&t.getContext("2d");return i&&i.canvas===t?(function(t,e){const i=t.style,s=t.getAttribute("height"),n=t.getAttribute("width");if(t[hs]={initial:{height:s,width:n,style:{display:i.display,height:i.height,width:i.width}}},i.display=i.display||"block",i.boxSizing=i.boxSizing||"border-box",ds(n)){const e=Pe(t,"width");void 0!==e&&(t.width=e)}if(ds(s))if(""===t.style.height)t.height=t.width/(e||2);else{const e=Pe(t,"height");void 0!==e&&(t.height=e)}}(t,e),i):null}releaseContext(t){const e=t.canvas;if(!e[hs])return!1;const i=e[hs].initial;["height","width"].forEach((t=>{const n=i[t];s(n)?e.removeAttribute(t):e.setAttribute(t,n)}));const n=i.style||{};return Object.keys(n).forEach((t=>{e.style[t]=n[t]})),e.width=e.width,delete e[hs],!0}addEventListener(t,e,i){this.removeEventListener(t,e);const s=t.$proxies||(t.$proxies={}),n={attach:ps,detach:ms,resize:ys}[e]||Ms;s[e]=n(t,e,i)}removeEventListener(t,e){const i=t.$proxies||(t.$proxies={}),s=i[e];if(!s)return;({attach:vs,detach:vs,resize:vs}[e]||fs)(t,e,s),i[e]=void 0}getDevicePixelRatio(){return window.devicePixelRatio}getMaximumSize(t,e,i,s){return we(t,e,i,s)}isAttached(t){const e=ge(t);return!(!e||!e.isConnected)}}function ks(t){return!fe()||"undefined"!=typeof OffscreenCanvas&&t instanceof OffscreenCanvas?ls:ws}var Ss=Object.freeze({__proto__:null,BasePlatform:rs,BasicPlatform:ls,DomPlatform:ws,_detectPlatform:ks});const Ps="transparent",Ds={boolean:(t,e,i)=>i>.5?e:t,color(t,e,i){const s=Qt(t||Ps),n=s.valid&&Qt(e||Ps);return n&&n.valid?n.mix(s,i).hexString():e},number:(t,e,i)=>t+(e-t)*i};class Cs{constructor(t,e,i,s){const n=e[i];s=Pi([t.to,s,n,t.from]);const o=Pi([t.from,n,s]);this._active=!0,this._fn=t.fn||Ds[t.type||typeof o],this._easing=fi[t.easing]||fi.linear,this._start=Math.floor(Date.now()+(t.delay||0)),this._duration=this._total=Math.floor(t.duration),this._loop=!!t.loop,this._target=e,this._prop=i,this._from=o,this._to=s,this._promises=void 0}active(){return this._active}update(t,e,i){if(this._active){this._notify(!1);const s=this._target[this._prop],n=i-this._start,o=this._duration-n;this._start=i,this._duration=Math.floor(Math.max(o,t.duration)),this._total+=n,this._loop=!!t.loop,this._to=Pi([t.to,e,s,t.from]),this._from=Pi([t.from,s,e])}}cancel(){this._active&&(this.tick(Date.now()),this._active=!1,this._notify(!1))}tick(t){const e=t-this._start,i=this._duration,s=this._prop,n=this._from,o=this._loop,a=this._to;let r;if(this._active=n!==a&&(o||e1?2-r:r,r=this._easing(Math.min(1,Math.max(0,r))),this._target[s]=this._fn(n,a,r))}wait(){const t=this._promises||(this._promises=[]);return new Promise(((e,i)=>{t.push({res:e,rej:i})}))}_notify(t){const e=t?"res":"rej",i=this._promises||[];for(let t=0;t{const a=t[s];if(!o(a))return;const r={};for(const t of e)r[t]=a[t];(n(a.properties)&&a.properties||[s]).forEach((t=>{t!==s&&i.has(t)||i.set(t,r)}))}))}_animateOptions(t,e){const i=e.options,s=function(t,e){if(!e)return;let i=t.options;if(!i)return void(t.options=e);i.$shared&&(t.options=i=Object.assign({},i,{$shared:!1,$animations:{}}));return i}(t,i);if(!s)return[];const n=this._createAnimations(s,i);return i.$shared&&function(t,e){const i=[],s=Object.keys(e);for(let e=0;e{t.options=i}),(()=>{})),n}_createAnimations(t,e){const i=this._properties,s=[],n=t.$animations||(t.$animations={}),o=Object.keys(e),a=Date.now();let r;for(r=o.length-1;r>=0;--r){const l=o[r];if("$"===l.charAt(0))continue;if("options"===l){s.push(...this._animateOptions(t,e));continue}const h=e[l];let c=n[l];const d=i.get(l);if(c){if(d&&c.active()){c.update(d,h,a);continue}c.cancel()}d&&d.duration?(n[l]=c=new Cs(d,t,l,h),s.push(c)):t[l]=h}return s}update(t,e){if(0===this._properties.size)return void Object.assign(t,e);const i=this._createAnimations(t,e);return i.length?(xt.add(this._chart,i),!0):void 0}}function As(t,e){const i=t&&t.options||{},s=i.reverse,n=void 0===i.min?e:0,o=void 0===i.max?e:0;return{start:s?o:n,end:s?n:o}}function Ts(t,e){const i=[],s=t._getSortedDatasetMetas(e);let n,o;for(n=0,o=s.length;n0||!i&&e<0)return n.index}return null}function zs(t,e){const{chart:i,_cachedMeta:s}=t,n=i._stacks||(i._stacks={}),{iScale:o,vScale:a,index:r}=s,l=o.axis,h=a.axis,c=function(t,e,i){return`${t.id}.${e.id}.${i.stack||i.type}`}(o,a,s),d=e.length;let u;for(let t=0;ti[t].axis===e)).shift()}function Vs(t,e){const i=t.controller.index,s=t.vScale&&t.vScale.axis;if(s){e=e||t._parsed;for(const t of e){const e=t._stacks;if(!e||void 0===e[s]||void 0===e[s][i])return;delete e[s][i],void 0!==e[s]._visualValues&&void 0!==e[s]._visualValues[i]&&delete e[s]._visualValues[i]}}}const Bs=t=>"reset"===t||"none"===t,Ws=(t,e)=>e?t:Object.assign({},t);class Ns{static defaults={};static datasetElementType=null;static dataElementType=null;constructor(t,e){this.chart=t,this._ctx=t.ctx,this.index=e,this._cachedDataOpts={},this._cachedMeta=this.getMeta(),this._type=this._cachedMeta.type,this.options=void 0,this._parsing=!1,this._data=void 0,this._objectData=void 0,this._sharedOptions=void 0,this._drawStart=void 0,this._drawCount=void 0,this.enableOptionSharing=!1,this.supportsDecimation=!1,this.$context=void 0,this._syncList=[],this.datasetElementType=new.target.datasetElementType,this.dataElementType=new.target.dataElementType,this.initialize()}initialize(){const t=this._cachedMeta;this.configure(),this.linkScales(),t._stacked=Es(t.vScale,t),this.addElements(),this.options.fill&&!this.chart.isPluginEnabled("filler")&&console.warn("Tried to use the 'fill' option without the 'Filler' plugin enabled. Please import and register the 'Filler' plugin and make sure it is not disabled in the options")}updateIndex(t){this.index!==t&&Vs(this._cachedMeta),this.index=t}linkScales(){const t=this.chart,e=this._cachedMeta,i=this.getDataset(),s=(t,e,i,s)=>"x"===t?e:"r"===t?s:i,n=e.xAxisID=l(i.xAxisID,Fs(t,"x")),o=e.yAxisID=l(i.yAxisID,Fs(t,"y")),a=e.rAxisID=l(i.rAxisID,Fs(t,"r")),r=e.indexAxis,h=e.iAxisID=s(r,n,o,a),c=e.vAxisID=s(r,o,n,a);e.xScale=this.getScaleForId(n),e.yScale=this.getScaleForId(o),e.rScale=this.getScaleForId(a),e.iScale=this.getScaleForId(h),e.vScale=this.getScaleForId(c)}getDataset(){return this.chart.data.datasets[this.index]}getMeta(){return this.chart.getDatasetMeta(this.index)}getScaleForId(t){return this.chart.scales[t]}_getOtherScale(t){const e=this._cachedMeta;return t===e.iScale?e.vScale:e.iScale}reset(){this._update("reset")}_destroy(){const t=this._cachedMeta;this._data&&rt(this._data,this),t._stacked&&Vs(t)}_dataCheck(){const t=this.getDataset(),e=t.data||(t.data=[]),i=this._data;if(o(e))this._data=function(t){const e=Object.keys(t),i=new Array(e.length);let s,n,o;for(s=0,n=e.length;s0&&i._parsed[t-1];if(!1===this._parsing)i._parsed=s,i._sorted=!0,d=s;else{d=n(s[t])?this.parseArrayData(i,s,t,e):o(s[t])?this.parseObjectData(i,s,t,e):this.parsePrimitiveData(i,s,t,e);const a=()=>null===c[l]||f&&c[l]t&&!e.hidden&&e._stacked&&{keys:Ts(i,!0),values:null})(e,i,this.chart),h={min:Number.POSITIVE_INFINITY,max:Number.NEGATIVE_INFINITY},{min:c,max:d}=function(t){const{min:e,max:i,minDefined:s,maxDefined:n}=t.getUserBounds();return{min:s?e:Number.NEGATIVE_INFINITY,max:n?i:Number.POSITIVE_INFINITY}}(r);let u,f;function g(){f=s[u];const e=f[r.axis];return!a(f[t.axis])||c>e||d=0;--u)if(!g()){this.updateRangeFromParsed(h,t,f,l);break}return h}getAllParsedValues(t){const e=this._cachedMeta._parsed,i=[];let s,n,o;for(s=0,n=e.length;s=0&&tthis.getContext(i,s,e)),c);return f.$shared&&(f.$shared=r,n[o]=Object.freeze(Ws(f,r))),f}_resolveAnimations(t,e,i){const s=this.chart,n=this._cachedDataOpts,o=`animation-${e}`,a=n[o];if(a)return a;let r;if(!1!==s.options.animation){const s=this.chart.config,n=s.datasetAnimationScopeKeys(this._type,e),o=s.getOptionScopes(this.getDataset(),n);r=s.createResolver(o,this.getContext(t,i,e))}const l=new Os(s,r&&r.animations);return r&&r._cacheable&&(n[o]=Object.freeze(l)),l}getSharedOptions(t){if(t.$shared)return this._sharedOptions||(this._sharedOptions=Object.assign({},t))}includeOptions(t,e){return!e||Bs(t)||this.chart._animationsDisabled}_getSharedOptions(t,e){const i=this.resolveDataElementOptions(t,e),s=this._sharedOptions,n=this.getSharedOptions(i),o=this.includeOptions(e,n)||n!==s;return this.updateSharedOptions(n,e,i),{sharedOptions:n,includeOptions:o}}updateElement(t,e,i,s){Bs(s)?Object.assign(t,i):this._resolveAnimations(e,s).update(t,i)}updateSharedOptions(t,e,i){t&&!Bs(e)&&this._resolveAnimations(void 0,e).update(t,i)}_setStyle(t,e,i,s){t.active=s;const n=this.getStyle(e,s);this._resolveAnimations(e,i,s).update(t,{options:!s&&this.getSharedOptions(n)||n})}removeHoverStyle(t,e,i){this._setStyle(t,i,"active",!1)}setHoverStyle(t,e,i){this._setStyle(t,i,"active",!0)}_removeDatasetHoverStyle(){const t=this._cachedMeta.dataset;t&&this._setStyle(t,void 0,"active",!1)}_setDatasetHoverStyle(){const t=this._cachedMeta.dataset;t&&this._setStyle(t,void 0,"active",!0)}_resyncElements(t){const e=this._data,i=this._cachedMeta.data;for(const[t,e,i]of this._syncList)this[t](e,i);this._syncList=[];const s=i.length,n=e.length,o=Math.min(n,s);o&&this.parse(0,o),n>s?this._insertElements(s,n-s,t):n{for(t.length+=e,a=t.length-1;a>=o;a--)t[a]=t[a-e]};for(r(n),a=t;a{s[t]=i[t]&&i[t].active()?i[t]._to:this[t]})),s}}function js(t,e){const i=t.options.ticks,n=function(t){const e=t.options.offset,i=t._tickSize(),s=t._length/i+(e?0:1),n=t._maxLength/i;return Math.floor(Math.min(s,n))}(t),o=Math.min(i.maxTicksLimit||n,n),a=i.major.enabled?function(t){const e=[];let i,s;for(i=0,s=t.length;io)return function(t,e,i,s){let n,o=0,a=i[0];for(s=Math.ceil(s),n=0;nn)return e}return Math.max(n,1)}(a,e,o);if(r>0){let t,i;const n=r>1?Math.round((h-l)/(r-1)):null;for($s(e,c,d,s(n)?0:l-n,l),t=0,i=r-1;t"top"===e||"left"===e?t[e]+i:t[e]-i,Us=(t,e)=>Math.min(e||t,t);function Xs(t,e){const i=[],s=t.length/e,n=t.length;let o=0;for(;oa+r)))return h}function Ks(t){return t.drawTicks?t.tickLength:0}function Gs(t,e){if(!t.display)return 0;const i=Si(t.font,e),s=ki(t.padding);return(n(t.text)?t.text.length:1)*i.lineHeight+s.height}function Zs(t,e,i){let s=ut(t);return(i&&"right"!==e||!i&&"right"===e)&&(s=(t=>"left"===t?"right":"right"===t?"left":t)(s)),s}class Js extends Hs{constructor(t){super(),this.id=t.id,this.type=t.type,this.options=void 0,this.ctx=t.ctx,this.chart=t.chart,this.top=void 0,this.bottom=void 0,this.left=void 0,this.right=void 0,this.width=void 0,this.height=void 0,this._margins={left:0,right:0,top:0,bottom:0},this.maxWidth=void 0,this.maxHeight=void 0,this.paddingTop=void 0,this.paddingBottom=void 0,this.paddingLeft=void 0,this.paddingRight=void 0,this.axis=void 0,this.labelRotation=void 0,this.min=void 0,this.max=void 0,this._range=void 0,this.ticks=[],this._gridLineItems=null,this._labelItems=null,this._labelSizes=null,this._length=0,this._maxLength=0,this._longestTextCache={},this._startPixel=void 0,this._endPixel=void 0,this._reversePixels=!1,this._userMax=void 0,this._userMin=void 0,this._suggestedMax=void 0,this._suggestedMin=void 0,this._ticksLength=0,this._borderValue=0,this._cache={},this._dataLimitsCached=!1,this.$context=void 0}init(t){this.options=t.setContext(this.getContext()),this.axis=t.axis,this._userMin=this.parse(t.min),this._userMax=this.parse(t.max),this._suggestedMin=this.parse(t.suggestedMin),this._suggestedMax=this.parse(t.suggestedMax)}parse(t,e){return t}getUserBounds(){let{_userMin:t,_userMax:e,_suggestedMin:i,_suggestedMax:s}=this;return t=r(t,Number.POSITIVE_INFINITY),e=r(e,Number.NEGATIVE_INFINITY),i=r(i,Number.POSITIVE_INFINITY),s=r(s,Number.NEGATIVE_INFINITY),{min:r(t,i),max:r(e,s),minDefined:a(t),maxDefined:a(e)}}getMinMax(t){let e,{min:i,max:s,minDefined:n,maxDefined:o}=this.getUserBounds();if(n&&o)return{min:i,max:s};const a=this.getMatchingVisibleMetas();for(let r=0,l=a.length;rs?s:i,s=n&&i>s?i:s,{min:r(i,r(s,i)),max:r(s,r(i,s))}}getPadding(){return{left:this.paddingLeft||0,top:this.paddingTop||0,right:this.paddingRight||0,bottom:this.paddingBottom||0}}getTicks(){return this.ticks}getLabels(){const t=this.chart.data;return this.options.labels||(this.isHorizontal()?t.xLabels:t.yLabels)||t.labels||[]}getLabelItems(t=this.chart.chartArea){return this._labelItems||(this._labelItems=this._computeLabelItems(t))}beforeLayout(){this._cache={},this._dataLimitsCached=!1}beforeUpdate(){d(this.options.beforeUpdate,[this])}update(t,e,i){const{beginAtZero:s,grace:n,ticks:o}=this.options,a=o.sampleSize;this.beforeUpdate(),this.maxWidth=t,this.maxHeight=e,this._margins=i=Object.assign({left:0,right:0,top:0,bottom:0},i),this.ticks=null,this._labelSizes=null,this._gridLineItems=null,this._labelItems=null,this.beforeSetDimensions(),this.setDimensions(),this.afterSetDimensions(),this._maxLength=this.isHorizontal()?this.width+i.left+i.right:this.height+i.top+i.bottom,this._dataLimitsCached||(this.beforeDataLimits(),this.determineDataLimits(),this.afterDataLimits(),this._range=Di(this,n,s),this._dataLimitsCached=!0),this.beforeBuildTicks(),this.ticks=this.buildTicks()||[],this.afterBuildTicks();const r=a=n||i<=1||!this.isHorizontal())return void(this.labelRotation=s);const h=this._getLabelSizes(),c=h.widest.width,d=h.highest.height,u=J(this.chart.width-c,0,this.maxWidth);o=t.offset?this.maxWidth/i:u/(i-1),c+6>o&&(o=u/(i-(t.offset?.5:1)),a=this.maxHeight-Ks(t.grid)-e.padding-Gs(t.title,this.chart.options.font),r=Math.sqrt(c*c+d*d),l=Y(Math.min(Math.asin(J((h.highest.height+6)/o,-1,1)),Math.asin(J(a/r,-1,1))-Math.asin(J(d/r,-1,1)))),l=Math.max(s,Math.min(n,l))),this.labelRotation=l}afterCalculateLabelRotation(){d(this.options.afterCalculateLabelRotation,[this])}afterAutoSkip(){}beforeFit(){d(this.options.beforeFit,[this])}fit(){const t={width:0,height:0},{chart:e,options:{ticks:i,title:s,grid:n}}=this,o=this._isVisible(),a=this.isHorizontal();if(o){const o=Gs(s,e.options.font);if(a?(t.width=this.maxWidth,t.height=Ks(n)+o):(t.height=this.maxHeight,t.width=Ks(n)+o),i.display&&this.ticks.length){const{first:e,last:s,widest:n,highest:o}=this._getLabelSizes(),r=2*i.padding,l=$(this.labelRotation),h=Math.cos(l),c=Math.sin(l);if(a){const e=i.mirror?0:c*n.width+h*o.height;t.height=Math.min(this.maxHeight,t.height+e+r)}else{const e=i.mirror?0:h*n.width+c*o.height;t.width=Math.min(this.maxWidth,t.width+e+r)}this._calculatePadding(e,s,c,h)}}this._handleMargins(),a?(this.width=this._length=e.width-this._margins.left-this._margins.right,this.height=t.height):(this.width=t.width,this.height=this._length=e.height-this._margins.top-this._margins.bottom)}_calculatePadding(t,e,i,s){const{ticks:{align:n,padding:o},position:a}=this.options,r=0!==this.labelRotation,l="top"!==a&&"x"===this.axis;if(this.isHorizontal()){const a=this.getPixelForTick(0)-this.left,h=this.right-this.getPixelForTick(this.ticks.length-1);let c=0,d=0;r?l?(c=s*t.width,d=i*e.height):(c=i*t.height,d=s*e.width):"start"===n?d=e.width:"end"===n?c=t.width:"inner"!==n&&(c=t.width/2,d=e.width/2),this.paddingLeft=Math.max((c-a+o)*this.width/(this.width-a),0),this.paddingRight=Math.max((d-h+o)*this.width/(this.width-h),0)}else{let i=e.height/2,s=t.height/2;"start"===n?(i=0,s=t.height):"end"===n&&(i=e.height,s=0),this.paddingTop=i+o,this.paddingBottom=s+o}}_handleMargins(){this._margins&&(this._margins.left=Math.max(this.paddingLeft,this._margins.left),this._margins.top=Math.max(this.paddingTop,this._margins.top),this._margins.right=Math.max(this.paddingRight,this._margins.right),this._margins.bottom=Math.max(this.paddingBottom,this._margins.bottom))}afterFit(){d(this.options.afterFit,[this])}isHorizontal(){const{axis:t,position:e}=this.options;return"top"===e||"bottom"===e||"x"===t}isFullSize(){return this.options.fullSize}_convertTicksToLabels(t){let e,i;for(this.beforeTickToLabelConversion(),this.generateTickLabels(t),e=0,i=t.length;e{const i=t.gc,s=i.length/2;let n;if(s>e){for(n=0;n({width:r[t]||0,height:l[t]||0});return{first:P(0),last:P(e-1),widest:P(k),highest:P(S),widths:r,heights:l}}getLabelForValue(t){return t}getPixelForValue(t,e){return NaN}getValueForPixel(t){}getPixelForTick(t){const e=this.ticks;return t<0||t>e.length-1?null:this.getPixelForValue(e[t].value)}getPixelForDecimal(t){this._reversePixels&&(t=1-t);const e=this._startPixel+t*this._length;return Q(this._alignToPixels?Ae(this.chart,e,0):e)}getDecimalForPixel(t){const e=(t-this._startPixel)/this._length;return this._reversePixels?1-e:e}getBasePixel(){return this.getPixelForValue(this.getBaseValue())}getBaseValue(){const{min:t,max:e}=this;return t<0&&e<0?e:t>0&&e>0?t:0}getContext(t){const e=this.ticks||[];if(t>=0&&ta*s?a/i:r/s:r*s0}_computeGridLineItems(t){const e=this.axis,i=this.chart,s=this.options,{grid:n,position:a,border:r}=s,h=n.offset,c=this.isHorizontal(),d=this.ticks.length+(h?1:0),u=Ks(n),f=[],g=r.setContext(this.getContext()),p=g.display?g.width:0,m=p/2,b=function(t){return Ae(i,t,p)};let x,_,y,v,M,w,k,S,P,D,C,O;if("top"===a)x=b(this.bottom),w=this.bottom-u,S=x-m,D=b(t.top)+m,O=t.bottom;else if("bottom"===a)x=b(this.top),D=t.top,O=b(t.bottom)-m,w=x+m,S=this.top+u;else if("left"===a)x=b(this.right),M=this.right-u,k=x-m,P=b(t.left)+m,C=t.right;else if("right"===a)x=b(this.left),P=t.left,C=b(t.right)-m,M=x+m,k=this.left+u;else if("x"===e){if("center"===a)x=b((t.top+t.bottom)/2+.5);else if(o(a)){const t=Object.keys(a)[0],e=a[t];x=b(this.chart.scales[t].getPixelForValue(e))}D=t.top,O=t.bottom,w=x+m,S=w+u}else if("y"===e){if("center"===a)x=b((t.left+t.right)/2);else if(o(a)){const t=Object.keys(a)[0],e=a[t];x=b(this.chart.scales[t].getPixelForValue(e))}M=x-m,k=M-u,P=t.left,C=t.right}const A=l(s.ticks.maxTicksLimit,d),T=Math.max(1,Math.ceil(d/A));for(_=0;_0&&(o-=s/2)}d={left:o,top:n,width:s+e.width,height:i+e.height,color:t.backdropColor}}b.push({label:v,font:P,textOffset:O,options:{rotation:m,color:i,strokeColor:o,strokeWidth:h,textAlign:f,textBaseline:A,translation:[M,w],backdrop:d}})}return b}_getXAxisLabelAlignment(){const{position:t,ticks:e}=this.options;if(-$(this.labelRotation))return"top"===t?"left":"right";let i="center";return"start"===e.align?i="left":"end"===e.align?i="right":"inner"===e.align&&(i="inner"),i}_getYAxisLabelAlignment(t){const{position:e,ticks:{crossAlign:i,mirror:s,padding:n}}=this.options,o=t+n,a=this._getLabelSizes().widest.width;let r,l;return"left"===e?s?(l=this.right+n,"near"===i?r="left":"center"===i?(r="center",l+=a/2):(r="right",l+=a)):(l=this.right-o,"near"===i?r="right":"center"===i?(r="center",l-=a/2):(r="left",l=this.left)):"right"===e?s?(l=this.left+n,"near"===i?r="right":"center"===i?(r="center",l-=a/2):(r="left",l-=a)):(l=this.left+o,"near"===i?r="left":"center"===i?(r="center",l+=a/2):(r="right",l=this.right)):r="right",{textAlign:r,x:l}}_computeLabelArea(){if(this.options.ticks.mirror)return;const t=this.chart,e=this.options.position;return"left"===e||"right"===e?{top:0,left:this.left,bottom:t.height,right:this.right}:"top"===e||"bottom"===e?{top:this.top,left:0,bottom:this.bottom,right:t.width}:void 0}drawBackground(){const{ctx:t,options:{backgroundColor:e},left:i,top:s,width:n,height:o}=this;e&&(t.save(),t.fillStyle=e,t.fillRect(i,s,n,o),t.restore())}getLineWidthForValue(t){const e=this.options.grid;if(!this._isVisible()||!e.display)return 0;const i=this.ticks.findIndex((e=>e.value===t));if(i>=0){return e.setContext(this.getContext(i)).lineWidth}return 0}drawGrid(t){const e=this.options.grid,i=this.ctx,s=this._gridLineItems||(this._gridLineItems=this._computeGridLineItems(t));let n,o;const a=(t,e,s)=>{s.width&&s.color&&(i.save(),i.lineWidth=s.width,i.strokeStyle=s.color,i.setLineDash(s.borderDash||[]),i.lineDashOffset=s.borderDashOffset,i.beginPath(),i.moveTo(t.x,t.y),i.lineTo(e.x,e.y),i.stroke(),i.restore())};if(e.display)for(n=0,o=s.length;n{this.drawBackground(),this.drawGrid(t),this.drawTitle()}},{z:s,draw:()=>{this.drawBorder()}},{z:e,draw:t=>{this.drawLabels(t)}}]:[{z:e,draw:t=>{this.draw(t)}}]}getMatchingVisibleMetas(t){const e=this.chart.getSortedVisibleDatasetMetas(),i=this.axis+"AxisID",s=[];let n,o;for(n=0,o=e.length;n{const s=i.split("."),n=s.pop(),o=[t].concat(s).join("."),a=e[i].split("."),r=a.pop(),l=a.join(".");ue.route(o,n,l,r)}))}(e,t.defaultRoutes);t.descriptors&&ue.describe(e,t.descriptors)}(t,o,i),this.override&&ue.override(t.id,t.overrides)),o}get(t){return this.items[t]}unregister(t){const e=this.items,i=t.id,s=this.scope;i in e&&delete e[i],s&&i in ue[s]&&(delete ue[s][i],this.override&&delete re[i])}}class tn{constructor(){this.controllers=new Qs(Ns,"datasets",!0),this.elements=new Qs(Hs,"elements"),this.plugins=new Qs(Object,"plugins"),this.scales=new Qs(Js,"scales"),this._typedRegistries=[this.controllers,this.scales,this.elements]}add(...t){this._each("register",t)}remove(...t){this._each("unregister",t)}addControllers(...t){this._each("register",t,this.controllers)}addElements(...t){this._each("register",t,this.elements)}addPlugins(...t){this._each("register",t,this.plugins)}addScales(...t){this._each("register",t,this.scales)}getController(t){return this._get(t,this.controllers,"controller")}getElement(t){return this._get(t,this.elements,"element")}getPlugin(t){return this._get(t,this.plugins,"plugin")}getScale(t){return this._get(t,this.scales,"scale")}removeControllers(...t){this._each("unregister",t,this.controllers)}removeElements(...t){this._each("unregister",t,this.elements)}removePlugins(...t){this._each("unregister",t,this.plugins)}removeScales(...t){this._each("unregister",t,this.scales)}_each(t,e,i){[...e].forEach((e=>{const s=i||this._getRegistryForType(e);i||s.isForType(e)||s===this.plugins&&e.id?this._exec(t,s,e):u(e,(e=>{const s=i||this._getRegistryForType(e);this._exec(t,s,e)}))}))}_exec(t,e,i){const s=w(t);d(i["before"+s],[],i),e[t](i),d(i["after"+s],[],i)}_getRegistryForType(t){for(let e=0;et.filter((t=>!e.some((e=>t.plugin.id===e.plugin.id))));this._notify(s(e,i),t,"stop"),this._notify(s(i,e),t,"start")}}function nn(t,e){return e||!1!==t?!0===t?{}:t:null}function on(t,{plugin:e,local:i},s,n){const o=t.pluginScopeKeys(e),a=t.getOptionScopes(s,o);return i&&e.defaults&&a.push(e.defaults),t.createResolver(a,n,[""],{scriptable:!1,indexable:!1,allKeys:!0})}function an(t,e){const i=ue.datasets[t]||{};return((e.datasets||{})[t]||{}).indexAxis||e.indexAxis||i.indexAxis||"x"}function rn(t){if("x"===t||"y"===t||"r"===t)return t}function ln(t,...e){if(rn(t))return t;for(const s of e){const e=s.axis||("top"===(i=s.position)||"bottom"===i?"x":"left"===i||"right"===i?"y":void 0)||t.length>1&&rn(t[0].toLowerCase());if(e)return e}var i;throw new Error(`Cannot determine type of '${t}' axis. Please provide 'axis' or 'position' option.`)}function hn(t,e,i){if(i[e+"AxisID"]===t)return{axis:e}}function cn(t,e){const i=re[t.type]||{scales:{}},s=e.scales||{},n=an(t.type,e),a=Object.create(null);return Object.keys(s).forEach((e=>{const r=s[e];if(!o(r))return console.error(`Invalid scale configuration for scale: ${e}`);if(r._proxy)return console.warn(`Ignoring resolver passed as options for scale: ${e}`);const l=ln(e,r,function(t,e){if(e.data&&e.data.datasets){const i=e.data.datasets.filter((e=>e.xAxisID===t||e.yAxisID===t));if(i.length)return hn(t,"x",i[0])||hn(t,"y",i[0])}return{}}(e,t),ue.scales[r.type]),h=function(t,e){return t===e?"_index_":"_value_"}(l,n),c=i.scales||{};a[e]=x(Object.create(null),[{axis:l},r,c[l],c[h]])})),t.data.datasets.forEach((i=>{const n=i.type||t.type,o=i.indexAxis||an(n,e),r=(re[n]||{}).scales||{};Object.keys(r).forEach((t=>{const e=function(t,e){let i=t;return"_index_"===t?i=e:"_value_"===t&&(i="x"===e?"y":"x"),i}(t,o),n=i[e+"AxisID"]||e;a[n]=a[n]||Object.create(null),x(a[n],[{axis:e},s[n],r[t]])}))})),Object.keys(a).forEach((t=>{const e=a[t];x(e,[ue.scales[e.type],ue.scale])})),a}function dn(t){const e=t.options||(t.options={});e.plugins=l(e.plugins,{}),e.scales=cn(t,e)}function un(t){return(t=t||{}).datasets=t.datasets||[],t.labels=t.labels||[],t}const fn=new Map,gn=new Set;function pn(t,e){let i=fn.get(t);return i||(i=e(),fn.set(t,i),gn.add(i)),i}const mn=(t,e,i)=>{const s=M(e,i);void 0!==s&&t.add(s)};class bn{constructor(t){this._config=function(t){return(t=t||{}).data=un(t.data),dn(t),t}(t),this._scopeCache=new Map,this._resolverCache=new Map}get platform(){return this._config.platform}get type(){return this._config.type}set type(t){this._config.type=t}get data(){return this._config.data}set data(t){this._config.data=un(t)}get options(){return this._config.options}set options(t){this._config.options=t}get plugins(){return this._config.plugins}update(){const t=this._config;this.clearCache(),dn(t)}clearCache(){this._scopeCache.clear(),this._resolverCache.clear()}datasetScopeKeys(t){return pn(t,(()=>[[`datasets.${t}`,""]]))}datasetAnimationScopeKeys(t,e){return pn(`${t}.transition.${e}`,(()=>[[`datasets.${t}.transitions.${e}`,`transitions.${e}`],[`datasets.${t}`,""]]))}datasetElementScopeKeys(t,e){return pn(`${t}-${e}`,(()=>[[`datasets.${t}.elements.${e}`,`datasets.${t}`,`elements.${e}`,""]]))}pluginScopeKeys(t){const e=t.id;return pn(`${this.type}-plugin-${e}`,(()=>[[`plugins.${e}`,...t.additionalOptionScopes||[]]]))}_cachedScopes(t,e){const i=this._scopeCache;let s=i.get(t);return s&&!e||(s=new Map,i.set(t,s)),s}getOptionScopes(t,e,i){const{options:s,type:n}=this,o=this._cachedScopes(t,i),a=o.get(e);if(a)return a;const r=new Set;e.forEach((e=>{t&&(r.add(t),e.forEach((e=>mn(r,t,e)))),e.forEach((t=>mn(r,s,t))),e.forEach((t=>mn(r,re[n]||{},t))),e.forEach((t=>mn(r,ue,t))),e.forEach((t=>mn(r,le,t)))}));const l=Array.from(r);return 0===l.length&&l.push(Object.create(null)),gn.has(e)&&o.set(e,l),l}chartOptionScopes(){const{options:t,type:e}=this;return[t,re[e]||{},ue.datasets[e]||{},{type:e},ue,le]}resolveNamedOptions(t,e,i,s=[""]){const o={$shared:!0},{resolver:a,subPrefixes:r}=xn(this._resolverCache,t,s);let l=a;if(function(t,e){const{isScriptable:i,isIndexable:s}=Ye(t);for(const o of e){const e=i(o),a=s(o),r=(a||e)&&t[o];if(e&&(S(r)||_n(r))||a&&n(r))return!0}return!1}(a,e)){o.$shared=!1;l=$e(a,i=S(i)?i():i,this.createResolver(t,i,r))}for(const t of e)o[t]=l[t];return o}createResolver(t,e,i=[""],s){const{resolver:n}=xn(this._resolverCache,t,i);return o(e)?$e(n,e,void 0,s):n}}function xn(t,e,i){let s=t.get(e);s||(s=new Map,t.set(e,s));const n=i.join();let o=s.get(n);if(!o){o={resolver:je(e,i),subPrefixes:i.filter((t=>!t.toLowerCase().includes("hover")))},s.set(n,o)}return o}const _n=t=>o(t)&&Object.getOwnPropertyNames(t).some((e=>S(t[e])));const yn=["top","bottom","left","right","chartArea"];function vn(t,e){return"top"===t||"bottom"===t||-1===yn.indexOf(t)&&"x"===e}function Mn(t,e){return function(i,s){return i[t]===s[t]?i[e]-s[e]:i[t]-s[t]}}function wn(t){const e=t.chart,i=e.options.animation;e.notifyPlugins("afterRender"),d(i&&i.onComplete,[t],e)}function kn(t){const e=t.chart,i=e.options.animation;d(i&&i.onProgress,[t],e)}function Sn(t){return fe()&&"string"==typeof t?t=document.getElementById(t):t&&t.length&&(t=t[0]),t&&t.canvas&&(t=t.canvas),t}const Pn={},Dn=t=>{const e=Sn(t);return Object.values(Pn).filter((t=>t.canvas===e)).pop()};function Cn(t,e,i){const s=Object.keys(t);for(const n of s){const s=+n;if(s>=e){const o=t[n];delete t[n],(i>0||s>e)&&(t[s+i]=o)}}}function On(t,e,i){return t.options.clip?t[i]:e[i]}class An{static defaults=ue;static instances=Pn;static overrides=re;static registry=en;static version="4.4.2";static getChart=Dn;static register(...t){en.add(...t),Tn()}static unregister(...t){en.remove(...t),Tn()}constructor(t,e){const s=this.config=new bn(e),n=Sn(t),o=Dn(n);if(o)throw new Error("Canvas is already in use. Chart with ID '"+o.id+"' must be destroyed before the canvas with ID '"+o.canvas.id+"' can be reused.");const a=s.createResolver(s.chartOptionScopes(),this.getContext());this.platform=new(s.platform||ks(n)),this.platform.updateConfig(s);const r=this.platform.acquireContext(n,a.aspectRatio),l=r&&r.canvas,h=l&&l.height,c=l&&l.width;this.id=i(),this.ctx=r,this.canvas=l,this.width=c,this.height=h,this._options=a,this._aspectRatio=this.aspectRatio,this._layers=[],this._metasets=[],this._stacks=void 0,this.boxes=[],this.currentDevicePixelRatio=void 0,this.chartArea=void 0,this._active=[],this._lastEvent=void 0,this._listeners={},this._responsiveListeners=void 0,this._sortedMetasets=[],this.scales={},this._plugins=new sn,this.$proxies={},this._hiddenIndices={},this.attached=!1,this._animationsDisabled=void 0,this.$context=void 0,this._doResize=dt((t=>this.update(t)),a.resizeDelay||0),this._dataChanges=[],Pn[this.id]=this,r&&l?(xt.listen(this,"complete",wn),xt.listen(this,"progress",kn),this._initialize(),this.attached&&this.update()):console.error("Failed to create chart: can't acquire context from the given item")}get aspectRatio(){const{options:{aspectRatio:t,maintainAspectRatio:e},width:i,height:n,_aspectRatio:o}=this;return s(t)?e&&o?o:n?i/n:null:t}get data(){return this.config.data}set data(t){this.config.data=t}get options(){return this._options}set options(t){this.config.options=t}get registry(){return en}_initialize(){return this.notifyPlugins("beforeInit"),this.options.responsive?this.resize():ke(this,this.options.devicePixelRatio),this.bindEvents(),this.notifyPlugins("afterInit"),this}clear(){return Te(this.canvas,this.ctx),this}stop(){return xt.stop(this),this}resize(t,e){xt.running(this)?this._resizeBeforeDraw={width:t,height:e}:this._resize(t,e)}_resize(t,e){const i=this.options,s=this.canvas,n=i.maintainAspectRatio&&this.aspectRatio,o=this.platform.getMaximumSize(s,t,e,n),a=i.devicePixelRatio||this.platform.getDevicePixelRatio(),r=this.width?"resize":"attach";this.width=o.width,this.height=o.height,this._aspectRatio=this.aspectRatio,ke(this,a,!0)&&(this.notifyPlugins("resize",{size:o}),d(i.onResize,[this,o],this),this.attached&&this._doResize(r)&&this.render())}ensureScalesHaveIDs(){u(this.options.scales||{},((t,e)=>{t.id=e}))}buildOrUpdateScales(){const t=this.options,e=t.scales,i=this.scales,s=Object.keys(i).reduce(((t,e)=>(t[e]=!1,t)),{});let n=[];e&&(n=n.concat(Object.keys(e).map((t=>{const i=e[t],s=ln(t,i),n="r"===s,o="x"===s;return{options:i,dposition:n?"chartArea":o?"bottom":"left",dtype:n?"radialLinear":o?"category":"linear"}})))),u(n,(e=>{const n=e.options,o=n.id,a=ln(o,n),r=l(n.type,e.dtype);void 0!==n.position&&vn(n.position,a)===vn(e.dposition)||(n.position=e.dposition),s[o]=!0;let h=null;if(o in i&&i[o].type===r)h=i[o];else{h=new(en.getScale(r))({id:o,type:r,ctx:this.ctx,chart:this}),i[h.id]=h}h.init(n,t)})),u(s,((t,e)=>{t||delete i[e]})),u(i,(t=>{as.configure(this,t,t.options),as.addBox(this,t)}))}_updateMetasets(){const t=this._metasets,e=this.data.datasets.length,i=t.length;if(t.sort(((t,e)=>t.index-e.index)),i>e){for(let t=e;te.length&&delete this._stacks,t.forEach(((t,i)=>{0===e.filter((e=>e===t._dataset)).length&&this._destroyDatasetMeta(i)}))}buildOrUpdateControllers(){const t=[],e=this.data.datasets;let i,s;for(this._removeUnreferencedMetasets(),i=0,s=e.length;i{this.getDatasetMeta(e).controller.reset()}),this)}reset(){this._resetElements(),this.notifyPlugins("reset")}update(t){const e=this.config;e.update();const i=this._options=e.createResolver(e.chartOptionScopes(),this.getContext()),s=this._animationsDisabled=!i.animation;if(this._updateScales(),this._checkEventBindings(),this._updateHiddenIndices(),this._plugins.invalidate(),!1===this.notifyPlugins("beforeUpdate",{mode:t,cancelable:!0}))return;const n=this.buildOrUpdateControllers();this.notifyPlugins("beforeElementsUpdate");let o=0;for(let t=0,e=this.data.datasets.length;t{t.reset()})),this._updateDatasets(t),this.notifyPlugins("afterUpdate",{mode:t}),this._layers.sort(Mn("z","_idx"));const{_active:a,_lastEvent:r}=this;r?this._eventHandler(r,!0):a.length&&this._updateHoverStyles(a,a,!0),this.render()}_updateScales(){u(this.scales,(t=>{as.removeBox(this,t)})),this.ensureScalesHaveIDs(),this.buildOrUpdateScales()}_checkEventBindings(){const t=this.options,e=new Set(Object.keys(this._listeners)),i=new Set(t.events);P(e,i)&&!!this._responsiveListeners===t.responsive||(this.unbindEvents(),this.bindEvents())}_updateHiddenIndices(){const{_hiddenIndices:t}=this,e=this._getUniformDataChanges()||[];for(const{method:i,start:s,count:n}of e){Cn(t,s,"_removeElements"===i?-n:n)}}_getUniformDataChanges(){const t=this._dataChanges;if(!t||!t.length)return;this._dataChanges=[];const e=this.data.datasets.length,i=e=>new Set(t.filter((t=>t[0]===e)).map(((t,e)=>e+","+t.splice(1).join(",")))),s=i(0);for(let t=1;tt.split(","))).map((t=>({method:t[1],start:+t[2],count:+t[3]})))}_updateLayout(t){if(!1===this.notifyPlugins("beforeLayout",{cancelable:!0}))return;as.update(this,this.width,this.height,t);const e=this.chartArea,i=e.width<=0||e.height<=0;this._layers=[],u(this.boxes,(t=>{i&&"chartArea"===t.position||(t.configure&&t.configure(),this._layers.push(...t._layers()))}),this),this._layers.forEach(((t,e)=>{t._idx=e})),this.notifyPlugins("afterLayout")}_updateDatasets(t){if(!1!==this.notifyPlugins("beforeDatasetsUpdate",{mode:t,cancelable:!0})){for(let t=0,e=this.data.datasets.length;t=0;--e)this._drawDataset(t[e]);this.notifyPlugins("afterDatasetsDraw")}_drawDataset(t){const e=this.ctx,i=t._clip,s=!i.disabled,n=function(t,e){const{xScale:i,yScale:s}=t;return i&&s?{left:On(i,e,"left"),right:On(i,e,"right"),top:On(s,e,"top"),bottom:On(s,e,"bottom")}:e}(t,this.chartArea),o={meta:t,index:t.index,cancelable:!0};!1!==this.notifyPlugins("beforeDatasetDraw",o)&&(s&&Ie(e,{left:!1===i.left?0:n.left-i.left,right:!1===i.right?this.width:n.right+i.right,top:!1===i.top?0:n.top-i.top,bottom:!1===i.bottom?this.height:n.bottom+i.bottom}),t.controller.draw(),s&&ze(e),o.cancelable=!1,this.notifyPlugins("afterDatasetDraw",o))}isPointInArea(t){return Re(t,this.chartArea,this._minPadding)}getElementsAtEventForMode(t,e,i,s){const n=Xi.modes[e];return"function"==typeof n?n(this,t,i,s):[]}getDatasetMeta(t){const e=this.data.datasets[t],i=this._metasets;let s=i.filter((t=>t&&t._dataset===e)).pop();return s||(s={type:null,data:[],dataset:null,controller:null,hidden:null,xAxisID:null,yAxisID:null,order:e&&e.order||0,index:t,_dataset:e,_parsed:[],_sorted:!1},i.push(s)),s}getContext(){return this.$context||(this.$context=Ci(null,{chart:this,type:"chart"}))}getVisibleDatasetCount(){return this.getSortedVisibleDatasetMetas().length}isDatasetVisible(t){const e=this.data.datasets[t];if(!e)return!1;const i=this.getDatasetMeta(t);return"boolean"==typeof i.hidden?!i.hidden:!e.hidden}setDatasetVisibility(t,e){this.getDatasetMeta(t).hidden=!e}toggleDataVisibility(t){this._hiddenIndices[t]=!this._hiddenIndices[t]}getDataVisibility(t){return!this._hiddenIndices[t]}_updateVisibility(t,e,i){const s=i?"show":"hide",n=this.getDatasetMeta(t),o=n.controller._resolveAnimations(void 0,s);k(e)?(n.data[e].hidden=!i,this.update()):(this.setDatasetVisibility(t,i),o.update(n,{visible:i}),this.update((e=>e.datasetIndex===t?s:void 0)))}hide(t,e){this._updateVisibility(t,e,!1)}show(t,e){this._updateVisibility(t,e,!0)}_destroyDatasetMeta(t){const e=this._metasets[t];e&&e.controller&&e.controller._destroy(),delete this._metasets[t]}_stop(){let t,e;for(this.stop(),xt.remove(this),t=0,e=this.data.datasets.length;t{e.addEventListener(this,i,s),t[i]=s},s=(t,e,i)=>{t.offsetX=e,t.offsetY=i,this._eventHandler(t)};u(this.options.events,(t=>i(t,s)))}bindResponsiveEvents(){this._responsiveListeners||(this._responsiveListeners={});const t=this._responsiveListeners,e=this.platform,i=(i,s)=>{e.addEventListener(this,i,s),t[i]=s},s=(i,s)=>{t[i]&&(e.removeEventListener(this,i,s),delete t[i])},n=(t,e)=>{this.canvas&&this.resize(t,e)};let o;const a=()=>{s("attach",a),this.attached=!0,this.resize(),i("resize",n),i("detach",o)};o=()=>{this.attached=!1,s("resize",n),this._stop(),this._resize(0,0),i("attach",a)},e.isAttached(this.canvas)?a():o()}unbindEvents(){u(this._listeners,((t,e)=>{this.platform.removeEventListener(this,e,t)})),this._listeners={},u(this._responsiveListeners,((t,e)=>{this.platform.removeEventListener(this,e,t)})),this._responsiveListeners=void 0}updateHoverStyle(t,e,i){const s=i?"set":"remove";let n,o,a,r;for("dataset"===e&&(n=this.getDatasetMeta(t[0].datasetIndex),n.controller["_"+s+"DatasetHoverStyle"]()),a=0,r=t.length;a{const i=this.getDatasetMeta(t);if(!i)throw new Error("No dataset found at index "+t);return{datasetIndex:t,element:i.data[e],index:e}}));!f(i,e)&&(this._active=i,this._lastEvent=null,this._updateHoverStyles(i,e))}notifyPlugins(t,e,i){return this._plugins.notify(this,t,e,i)}isPluginEnabled(t){return 1===this._plugins._cache.filter((e=>e.plugin.id===t)).length}_updateHoverStyles(t,e,i){const s=this.options.hover,n=(t,e)=>t.filter((t=>!e.some((e=>t.datasetIndex===e.datasetIndex&&t.index===e.index)))),o=n(e,t),a=i?t:n(t,e);o.length&&this.updateHoverStyle(o,s.mode,!1),a.length&&s.mode&&this.updateHoverStyle(a,s.mode,!0)}_eventHandler(t,e){const i={event:t,replay:e,cancelable:!0,inChartArea:this.isPointInArea(t)},s=e=>(e.options.events||this.options.events).includes(t.native.type);if(!1===this.notifyPlugins("beforeEvent",i,s))return;const n=this._handleEvent(t,e,i.inChartArea);return i.cancelable=!1,this.notifyPlugins("afterEvent",i,s),(n||i.changed)&&this.render(),this}_handleEvent(t,e,i){const{_active:s=[],options:n}=this,o=e,a=this._getActiveElements(t,s,i,o),r=D(t),l=function(t,e,i,s){return i&&"mouseout"!==t.type?s?e:t:null}(t,this._lastEvent,i,r);i&&(this._lastEvent=null,d(n.onHover,[t,a,this],this),r&&d(n.onClick,[t,a,this],this));const h=!f(a,s);return(h||e)&&(this._active=a,this._updateHoverStyles(a,s,e)),this._lastEvent=l,h}_getActiveElements(t,e,i,s){if("mouseout"===t.type)return[];if(!i)return e;const n=this.options.hover;return this.getElementsAtEventForMode(t,n.mode,n,s)}}function Tn(){return u(An.instances,(t=>t._plugins.invalidate()))}function Ln(){throw new Error("This method is not implemented: Check that a complete date adapter is provided.")}class En{static override(t){Object.assign(En.prototype,t)}options;constructor(t){this.options=t||{}}init(){}formats(){return Ln()}parse(){return Ln()}format(){return Ln()}add(){return Ln()}diff(){return Ln()}startOf(){return Ln()}endOf(){return Ln()}}var Rn={_date:En};function In(t){const e=t.iScale,i=function(t,e){if(!t._cache.$bar){const i=t.getMatchingVisibleMetas(e);let s=[];for(let e=0,n=i.length;et-e)))}return t._cache.$bar}(e,t.type);let s,n,o,a,r=e._length;const l=()=>{32767!==o&&-32768!==o&&(k(a)&&(r=Math.min(r,Math.abs(o-a)||r)),a=o)};for(s=0,n=i.length;sMath.abs(r)&&(l=r,h=a),e[i.axis]=h,e._custom={barStart:l,barEnd:h,start:n,end:o,min:a,max:r}}(t,e,i,s):e[i.axis]=i.parse(t,s),e}function Fn(t,e,i,s){const n=t.iScale,o=t.vScale,a=n.getLabels(),r=n===o,l=[];let h,c,d,u;for(h=i,c=i+s;ht.x,i="left",s="right"):(e=t.base"spacing"!==t,_indexable:t=>"spacing"!==t&&!t.startsWith("borderDash")&&!t.startsWith("hoverBorderDash")};static overrides={aspectRatio:1,plugins:{legend:{labels:{generateLabels(t){const e=t.data;if(e.labels.length&&e.datasets.length){const{labels:{pointStyle:i,color:s}}=t.legend.options;return e.labels.map(((e,n)=>{const o=t.getDatasetMeta(0).controller.getStyle(n);return{text:e,fillStyle:o.backgroundColor,strokeStyle:o.borderColor,fontColor:s,lineWidth:o.borderWidth,pointStyle:i,hidden:!t.getDataVisibility(n),index:n}}))}return[]}},onClick(t,e,i){i.chart.toggleDataVisibility(e.index),i.chart.update()}}}};constructor(t,e){super(t,e),this.enableOptionSharing=!0,this.innerRadius=void 0,this.outerRadius=void 0,this.offsetX=void 0,this.offsetY=void 0}linkScales(){}parse(t,e){const i=this.getDataset().data,s=this._cachedMeta;if(!1===this._parsing)s._parsed=i;else{let n,a,r=t=>+i[t];if(o(i[t])){const{key:t="value"}=this._parsing;r=e=>+M(i[e],t)}for(n=t,a=t+e;nZ(t,r,l,!0)?1:Math.max(e,e*i,s,s*i),g=(t,e,s)=>Z(t,r,l,!0)?-1:Math.min(e,e*i,s,s*i),p=f(0,h,d),m=f(E,c,u),b=g(C,h,d),x=g(C+E,c,u);s=(p-b)/2,n=(m-x)/2,o=-(p+b)/2,a=-(m+x)/2}return{ratioX:s,ratioY:n,offsetX:o,offsetY:a}}(u,d,r),b=(i.width-o)/f,x=(i.height-o)/g,_=Math.max(Math.min(b,x)/2,0),y=c(this.options.radius,_),v=(y-Math.max(y*r,0))/this._getVisibleDatasetWeightTotal();this.offsetX=p*y,this.offsetY=m*y,s.total=this.calculateTotal(),this.outerRadius=y-v*this._getRingWeightOffset(this.index),this.innerRadius=Math.max(this.outerRadius-v*l,0),this.updateElements(n,0,n.length,t)}_circumference(t,e){const i=this.options,s=this._cachedMeta,n=this._getCircumference();return e&&i.animation.animateRotate||!this.chart.getDataVisibility(t)||null===s._parsed[t]||s.data[t].hidden?0:this.calculateCircumference(s._parsed[t]*n/O)}updateElements(t,e,i,s){const n="reset"===s,o=this.chart,a=o.chartArea,r=o.options.animation,l=(a.left+a.right)/2,h=(a.top+a.bottom)/2,c=n&&r.animateScale,d=c?0:this.innerRadius,u=c?0:this.outerRadius,{sharedOptions:f,includeOptions:g}=this._getSharedOptions(e,s);let p,m=this._getRotation();for(p=0;p0&&!isNaN(t)?O*(Math.abs(t)/e):0}getLabelAndValue(t){const e=this._cachedMeta,i=this.chart,s=i.data.labels||[],n=ne(e._parsed[t],i.options.locale);return{label:s[t]||"",value:n}}getMaxBorderWidth(t){let e=0;const i=this.chart;let s,n,o,a,r;if(!t)for(s=0,n=i.data.datasets.length;s{const o=t.getDatasetMeta(0).controller.getStyle(n);return{text:e,fillStyle:o.backgroundColor,strokeStyle:o.borderColor,fontColor:s,lineWidth:o.borderWidth,pointStyle:i,hidden:!t.getDataVisibility(n),index:n}}))}return[]}},onClick(t,e,i){i.chart.toggleDataVisibility(e.index),i.chart.update()}}},scales:{r:{type:"radialLinear",angleLines:{display:!1},beginAtZero:!0,grid:{circular:!0},pointLabels:{display:!1},startAngle:0}}};constructor(t,e){super(t,e),this.innerRadius=void 0,this.outerRadius=void 0}getLabelAndValue(t){const e=this._cachedMeta,i=this.chart,s=i.data.labels||[],n=ne(e._parsed[t].r,i.options.locale);return{label:s[t]||"",value:n}}parseObjectData(t,e,i,s){return ii.bind(this)(t,e,i,s)}update(t){const e=this._cachedMeta.data;this._updateRadius(),this.updateElements(e,0,e.length,t)}getMinMax(){const t=this._cachedMeta,e={min:Number.POSITIVE_INFINITY,max:Number.NEGATIVE_INFINITY};return t.data.forEach(((t,i)=>{const s=this.getParsed(i).r;!isNaN(s)&&this.chart.getDataVisibility(i)&&(se.max&&(e.max=s))})),e}_updateRadius(){const t=this.chart,e=t.chartArea,i=t.options,s=Math.min(e.right-e.left,e.bottom-e.top),n=Math.max(s/2,0),o=(n-Math.max(i.cutoutPercentage?n/100*i.cutoutPercentage:1,0))/t.getVisibleDatasetCount();this.outerRadius=n-o*this.index,this.innerRadius=this.outerRadius-o}updateElements(t,e,i,s){const n="reset"===s,o=this.chart,a=o.options.animation,r=this._cachedMeta.rScale,l=r.xCenter,h=r.yCenter,c=r.getIndexAngle(0)-.5*C;let d,u=c;const f=360/this.countVisibleElements();for(d=0;d{!isNaN(this.getParsed(i).r)&&this.chart.getDataVisibility(i)&&e++})),e}_computeAngle(t,e,i){return this.chart.getDataVisibility(t)?$(this.resolveDataElementOptions(t,e).angle||i):0}}var Yn=Object.freeze({__proto__:null,BarController:class extends Ns{static id="bar";static defaults={datasetElementType:!1,dataElementType:"bar",categoryPercentage:.8,barPercentage:.9,grouped:!0,animations:{numbers:{type:"number",properties:["x","y","base","width","height"]}}};static overrides={scales:{_index_:{type:"category",offset:!0,grid:{offset:!0}},_value_:{type:"linear",beginAtZero:!0}}};parsePrimitiveData(t,e,i,s){return Fn(t,e,i,s)}parseArrayData(t,e,i,s){return Fn(t,e,i,s)}parseObjectData(t,e,i,s){const{iScale:n,vScale:o}=t,{xAxisKey:a="x",yAxisKey:r="y"}=this._parsing,l="x"===n.axis?a:r,h="x"===o.axis?a:r,c=[];let d,u,f,g;for(d=i,u=i+s;dt.controller.options.grouped)),o=i.options.stacked,a=[],r=t=>{const i=t.controller.getParsed(e),n=i&&i[t.vScale.axis];if(s(n)||isNaN(n))return!0};for(const i of n)if((void 0===e||!r(i))&&((!1===o||-1===a.indexOf(i.stack)||void 0===o&&void 0===i.stack)&&a.push(i.stack),i.index===t))break;return a.length||a.push(void 0),a}_getStackCount(t){return this._getStacks(void 0,t).length}_getStackIndex(t,e,i){const s=this._getStacks(t,i),n=void 0!==e?s.indexOf(e):-1;return-1===n?s.length-1:n}_getRuler(){const t=this.options,e=this._cachedMeta,i=e.iScale,s=[];let n,o;for(n=0,o=e.data.length;n=i?1:-1)}(u,e,r)*a,f===r&&(b-=u/2);const t=e.getPixelForDecimal(0),s=e.getPixelForDecimal(1),o=Math.min(t,s),h=Math.max(t,s);b=Math.max(Math.min(b,h),o),d=b+u,i&&!c&&(l._stacks[e.axis]._visualValues[n]=e.getValueForPixel(d)-e.getValueForPixel(b))}if(b===e.getPixelForValue(r)){const t=F(u)*e.getLineWidthForValue(r)/2;b+=t,u-=t}return{size:u,base:b,head:d,center:d+u/2}}_calculateBarIndexPixels(t,e){const i=e.scale,n=this.options,o=n.skipNull,a=l(n.maxBarThickness,1/0);let r,h;if(e.grouped){const i=o?this._getStackCount(t):e.stackCount,l="flex"===n.barThickness?function(t,e,i,s){const n=e.pixels,o=n[t];let a=t>0?n[t-1]:null,r=t=0;--i)e=Math.max(e,t[i].size(this.resolveDataElementOptions(i))/2);return e>0&&e}getLabelAndValue(t){const e=this._cachedMeta,i=this.chart.data.labels||[],{xScale:s,yScale:n}=e,o=this.getParsed(t),a=s.getLabelForValue(o.x),r=n.getLabelForValue(o.y),l=o._custom;return{label:i[t]||"",value:"("+a+", "+r+(l?", "+l:"")+")"}}update(t){const e=this._cachedMeta.data;this.updateElements(e,0,e.length,t)}updateElements(t,e,i,s){const n="reset"===s,{iScale:o,vScale:a}=this._cachedMeta,{sharedOptions:r,includeOptions:l}=this._getSharedOptions(e,s),h=o.axis,c=a.axis;for(let d=e;d0&&this.getParsed(e-1);for(let i=0;i<_;++i){const g=t[i],_=b?g:{};if(i=x){_.skip=!0;continue}const v=this.getParsed(i),M=s(v[f]),w=_[u]=a.getPixelForValue(v[u],i),k=_[f]=o||M?r.getBasePixel():r.getPixelForValue(l?this.applyStack(r,v,l):v[f],i);_.skip=isNaN(w)||isNaN(k)||M,_.stop=i>0&&Math.abs(v[u]-y[u])>m,p&&(_.parsed=v,_.raw=h.data[i]),d&&(_.options=c||this.resolveDataElementOptions(i,g.active?"active":n)),b||this.updateElement(g,i,_,n),y=v}}getMaxOverflow(){const t=this._cachedMeta,e=t.dataset,i=e.options&&e.options.borderWidth||0,s=t.data||[];if(!s.length)return i;const n=s[0].size(this.resolveDataElementOptions(0)),o=s[s.length-1].size(this.resolveDataElementOptions(s.length-1));return Math.max(i,n,o)/2}draw(){const t=this._cachedMeta;t.dataset.updateControlPoints(this.chart.chartArea,t.iScale.axis),super.draw()}},PieController:class extends jn{static id="pie";static defaults={cutout:0,rotation:0,circumference:360,radius:"100%"}},PolarAreaController:$n,RadarController:class extends Ns{static id="radar";static defaults={datasetElementType:"line",dataElementType:"point",indexAxis:"r",showLine:!0,elements:{line:{fill:"start"}}};static overrides={aspectRatio:1,scales:{r:{type:"radialLinear"}}};getLabelAndValue(t){const e=this._cachedMeta.vScale,i=this.getParsed(t);return{label:e.getLabels()[t],value:""+e.getLabelForValue(i[e.axis])}}parseObjectData(t,e,i,s){return ii.bind(this)(t,e,i,s)}update(t){const e=this._cachedMeta,i=e.dataset,s=e.data||[],n=e.iScale.getLabels();if(i.points=s,"resize"!==t){const e=this.resolveDatasetElementOptions(t);this.options.showLine||(e.borderWidth=0);const o={_loop:!0,_fullLoop:n.length===s.length,options:e};this.updateElement(i,void 0,o,t)}this.updateElements(s,0,s.length,t)}updateElements(t,e,i,s){const n=this._cachedMeta.rScale,o="reset"===s;for(let a=e;a0&&this.getParsed(e-1);for(let c=e;c0&&Math.abs(i[f]-_[f])>b,m&&(p.parsed=i,p.raw=h.data[c]),u&&(p.options=d||this.resolveDataElementOptions(c,e.active?"active":n)),x||this.updateElement(e,c,p,n),_=i}this.updateSharedOptions(d,n,c)}getMaxOverflow(){const t=this._cachedMeta,e=t.data||[];if(!this.options.showLine){let t=0;for(let i=e.length-1;i>=0;--i)t=Math.max(t,e[i].size(this.resolveDataElementOptions(i))/2);return t>0&&t}const i=t.dataset,s=i.options&&i.options.borderWidth||0;if(!e.length)return s;const n=e[0].size(this.resolveDataElementOptions(0)),o=e[e.length-1].size(this.resolveDataElementOptions(e.length-1));return Math.max(s,n,o)/2}}});function Un(t,e,i,s){const n=vi(t.options.borderRadius,["outerStart","outerEnd","innerStart","innerEnd"]);const o=(i-e)/2,a=Math.min(o,s*e/2),r=t=>{const e=(i-Math.min(o,t))*s/2;return J(t,0,Math.min(o,e))};return{outerStart:r(n.outerStart),outerEnd:r(n.outerEnd),innerStart:J(n.innerStart,0,a),innerEnd:J(n.innerEnd,0,a)}}function Xn(t,e,i,s){return{x:i+t*Math.cos(e),y:s+t*Math.sin(e)}}function qn(t,e,i,s,n,o){const{x:a,y:r,startAngle:l,pixelMargin:h,innerRadius:c}=e,d=Math.max(e.outerRadius+s+i-h,0),u=c>0?c+s+i+h:0;let f=0;const g=n-l;if(s){const t=((c>0?c-s:0)+(d>0?d-s:0))/2;f=(g-(0!==t?g*t/(t+s):g))/2}const p=(g-Math.max(.001,g*d-i/C)/d)/2,m=l+p+f,b=n-p-f,{outerStart:x,outerEnd:_,innerStart:y,innerEnd:v}=Un(e,u,d,b-m),M=d-x,w=d-_,k=m+x/M,S=b-_/w,P=u+y,D=u+v,O=m+y/P,A=b-v/D;if(t.beginPath(),o){const e=(k+S)/2;if(t.arc(a,r,d,k,e),t.arc(a,r,d,e,S),_>0){const e=Xn(w,S,a,r);t.arc(e.x,e.y,_,S,b+E)}const i=Xn(D,b,a,r);if(t.lineTo(i.x,i.y),v>0){const e=Xn(D,A,a,r);t.arc(e.x,e.y,v,b+E,A+Math.PI)}const s=(b-v/u+(m+y/u))/2;if(t.arc(a,r,u,b-v/u,s,!0),t.arc(a,r,u,s,m+y/u,!0),y>0){const e=Xn(P,O,a,r);t.arc(e.x,e.y,y,O+Math.PI,m-E)}const n=Xn(M,m,a,r);if(t.lineTo(n.x,n.y),x>0){const e=Xn(M,k,a,r);t.arc(e.x,e.y,x,m-E,k)}}else{t.moveTo(a,r);const e=Math.cos(k)*d+a,i=Math.sin(k)*d+r;t.lineTo(e,i);const s=Math.cos(S)*d+a,n=Math.sin(S)*d+r;t.lineTo(s,n)}t.closePath()}function Kn(t,e,i,s,n){const{fullCircles:o,startAngle:a,circumference:r,options:l}=e,{borderWidth:h,borderJoinStyle:c,borderDash:d,borderDashOffset:u}=l,f="inner"===l.borderAlign;if(!h)return;t.setLineDash(d||[]),t.lineDashOffset=u,f?(t.lineWidth=2*h,t.lineJoin=c||"round"):(t.lineWidth=h,t.lineJoin=c||"bevel");let g=e.endAngle;if(o){qn(t,e,i,s,g,n);for(let e=0;en?(h=n/l,t.arc(o,a,l,i+h,s-h,!0)):t.arc(o,a,n,i+E,s-E),t.closePath(),t.clip()}(t,e,g),o||(qn(t,e,i,s,g,n),t.stroke())}function Gn(t,e,i=e){t.lineCap=l(i.borderCapStyle,e.borderCapStyle),t.setLineDash(l(i.borderDash,e.borderDash)),t.lineDashOffset=l(i.borderDashOffset,e.borderDashOffset),t.lineJoin=l(i.borderJoinStyle,e.borderJoinStyle),t.lineWidth=l(i.borderWidth,e.borderWidth),t.strokeStyle=l(i.borderColor,e.borderColor)}function Zn(t,e,i){t.lineTo(i.x,i.y)}function Jn(t,e,i={}){const s=t.length,{start:n=0,end:o=s-1}=i,{start:a,end:r}=e,l=Math.max(n,a),h=Math.min(o,r),c=nr&&o>r;return{count:s,start:l,loop:e.loop,ilen:h(a+(h?r-t:t))%o,_=()=>{f!==g&&(t.lineTo(m,g),t.lineTo(m,f),t.lineTo(m,p))};for(l&&(d=n[x(0)],t.moveTo(d.x,d.y)),c=0;c<=r;++c){if(d=n[x(c)],d.skip)continue;const e=d.x,i=d.y,s=0|e;s===u?(ig&&(g=i),m=(b*m+e)/++b):(_(),t.lineTo(e,i),u=s,b=0,f=g=i),p=i}_()}function eo(t){const e=t.options,i=e.borderDash&&e.borderDash.length;return!(t._decimated||t._loop||e.tension||"monotone"===e.cubicInterpolationMode||e.stepped||i)?to:Qn}const io="function"==typeof Path2D;function so(t,e,i,s){io&&!e.options.segment?function(t,e,i,s){let n=e._path;n||(n=e._path=new Path2D,e.path(n,i,s)&&n.closePath()),Gn(t,e.options),t.stroke(n)}(t,e,i,s):function(t,e,i,s){const{segments:n,options:o}=e,a=eo(e);for(const r of n)Gn(t,o,r.style),t.beginPath(),a(t,e,r,{start:i,end:i+s-1})&&t.closePath(),t.stroke()}(t,e,i,s)}class no extends Hs{static id="line";static defaults={borderCapStyle:"butt",borderDash:[],borderDashOffset:0,borderJoinStyle:"miter",borderWidth:3,capBezierPoints:!0,cubicInterpolationMode:"default",fill:!1,spanGaps:!1,stepped:!1,tension:0};static defaultRoutes={backgroundColor:"backgroundColor",borderColor:"borderColor"};static descriptors={_scriptable:!0,_indexable:t=>"borderDash"!==t&&"fill"!==t};constructor(t){super(),this.animated=!0,this.options=void 0,this._chart=void 0,this._loop=void 0,this._fullLoop=void 0,this._path=void 0,this._points=void 0,this._segments=void 0,this._decimated=!1,this._pointsUpdated=!1,this._datasetIndex=void 0,t&&Object.assign(this,t)}updateControlPoints(t,e){const i=this.options;if((i.tension||"monotone"===i.cubicInterpolationMode)&&!i.stepped&&!this._pointsUpdated){const s=i.spanGaps?this._loop:this._fullLoop;hi(this._points,i,t,s,e),this._pointsUpdated=!0}}set points(t){this._points=t,delete this._segments,delete this._path,this._pointsUpdated=!1}get points(){return this._points}get segments(){return this._segments||(this._segments=zi(this,this.options.segment))}first(){const t=this.segments,e=this.points;return t.length&&e[t[0].start]}last(){const t=this.segments,e=this.points,i=t.length;return i&&e[t[i-1].end]}interpolate(t,e){const i=this.options,s=t[e],n=this.points,o=Ii(this,{property:e,start:s,end:s});if(!o.length)return;const a=[],r=function(t){return t.stepped?pi:t.tension||"monotone"===t.cubicInterpolationMode?mi:gi}(i);let l,h;for(l=0,h=o.length;l"borderDash"!==t};circumference;endAngle;fullCircles;innerRadius;outerRadius;pixelMargin;startAngle;constructor(t){super(),this.options=void 0,this.circumference=void 0,this.startAngle=void 0,this.endAngle=void 0,this.innerRadius=void 0,this.outerRadius=void 0,this.pixelMargin=0,this.fullCircles=0,t&&Object.assign(this,t)}inRange(t,e,i){const s=this.getProps(["x","y"],i),{angle:n,distance:o}=X(s,{x:t,y:e}),{startAngle:a,endAngle:r,innerRadius:h,outerRadius:c,circumference:d}=this.getProps(["startAngle","endAngle","innerRadius","outerRadius","circumference"],i),u=(this.options.spacing+this.options.borderWidth)/2,f=l(d,r-a)>=O||Z(n,a,r),g=tt(o,h+u,c+u);return f&&g}getCenterPoint(t){const{x:e,y:i,startAngle:s,endAngle:n,innerRadius:o,outerRadius:a}=this.getProps(["x","y","startAngle","endAngle","innerRadius","outerRadius"],t),{offset:r,spacing:l}=this.options,h=(s+n)/2,c=(o+a+l+r)/2;return{x:e+Math.cos(h)*c,y:i+Math.sin(h)*c}}tooltipPosition(t){return this.getCenterPoint(t)}draw(t){const{options:e,circumference:i}=this,s=(e.offset||0)/4,n=(e.spacing||0)/2,o=e.circular;if(this.pixelMargin="inner"===e.borderAlign?.33:0,this.fullCircles=i>O?Math.floor(i/O):0,0===i||this.innerRadius<0||this.outerRadius<0)return;t.save();const a=(this.startAngle+this.endAngle)/2;t.translate(Math.cos(a)*s,Math.sin(a)*s);const r=s*(1-Math.sin(Math.min(C,i||0)));t.fillStyle=e.backgroundColor,t.strokeStyle=e.borderColor,function(t,e,i,s,n){const{fullCircles:o,startAngle:a,circumference:r}=e;let l=e.endAngle;if(o){qn(t,e,i,s,l,n);for(let e=0;e("string"==typeof e?(i=t.push(e)-1,s.unshift({index:i,label:e})):isNaN(e)&&(i=null),i))(t,e,i,s);return n!==t.lastIndexOf(e)?i:n}function po(t){const e=this.getLabels();return t>=0&&ts=e?s:t,a=t=>n=i?n:t;if(t){const t=F(s),e=F(n);t<0&&e<0?a(0):t>0&&e>0&&o(0)}if(s===n){let e=0===n?1:Math.abs(.05*n);a(n+e),t||o(s-e)}this.min=s,this.max=n}getTickLimit(){const t=this.options.ticks;let e,{maxTicksLimit:i,stepSize:s}=t;return s?(e=Math.ceil(this.max/s)-Math.floor(this.min/s)+1,e>1e3&&(console.warn(`scales.${this.id}.ticks.stepSize: ${s} would result generating up to ${e} ticks. Limiting to 1000.`),e=1e3)):(e=this.computeTickLimit(),i=i||11),i&&(e=Math.min(i,e)),e}computeTickLimit(){return Number.POSITIVE_INFINITY}buildTicks(){const t=this.options,e=t.ticks;let i=this.getTickLimit();i=Math.max(2,i);const n=function(t,e){const i=[],{bounds:n,step:o,min:a,max:r,precision:l,count:h,maxTicks:c,maxDigits:d,includeBounds:u}=t,f=o||1,g=c-1,{min:p,max:m}=e,b=!s(a),x=!s(r),_=!s(h),y=(m-p)/(d+1);let v,M,w,k,S=B((m-p)/g/f)*f;if(S<1e-14&&!b&&!x)return[{value:p},{value:m}];k=Math.ceil(m/S)-Math.floor(p/S),k>g&&(S=B(k*S/g/f)*f),s(l)||(v=Math.pow(10,l),S=Math.ceil(S*v)/v),"ticks"===n?(M=Math.floor(p/S)*S,w=Math.ceil(m/S)*S):(M=p,w=m),b&&x&&o&&H((r-a)/o,S/1e3)?(k=Math.round(Math.min((r-a)/S,c)),S=(r-a)/k,M=a,w=r):_?(M=b?a:M,w=x?r:w,k=h-1,S=(w-M)/k):(k=(w-M)/S,k=V(k,Math.round(k),S/1e3)?Math.round(k):Math.ceil(k));const P=Math.max(U(S),U(M));v=Math.pow(10,s(l)?P:l),M=Math.round(M*v)/v,w=Math.round(w*v)/v;let D=0;for(b&&(u&&M!==a?(i.push({value:a}),Mr)break;i.push({value:t})}return x&&u&&w!==r?i.length&&V(i[i.length-1].value,r,mo(r,y,t))?i[i.length-1].value=r:i.push({value:r}):x&&w!==r||i.push({value:w}),i}({maxTicks:i,bounds:t.bounds,min:t.min,max:t.max,precision:e.precision,step:e.stepSize,count:e.count,maxDigits:this._maxDigits(),horizontal:this.isHorizontal(),minRotation:e.minRotation||0,includeBounds:!1!==e.includeBounds},this._range||this);return"ticks"===t.bounds&&j(n,this,"value"),t.reverse?(n.reverse(),this.start=this.max,this.end=this.min):(this.start=this.min,this.end=this.max),n}configure(){const t=this.ticks;let e=this.min,i=this.max;if(super.configure(),this.options.offset&&t.length){const s=(i-e)/Math.max(t.length-1,1)/2;e-=s,i+=s}this._startValue=e,this._endValue=i,this._valueRange=i-e}getLabelForValue(t){return ne(t,this.chart.options.locale,this.options.ticks.format)}}class xo extends bo{static id="linear";static defaults={ticks:{callback:ae.formatters.numeric}};determineDataLimits(){const{min:t,max:e}=this.getMinMax(!0);this.min=a(t)?t:0,this.max=a(e)?e:1,this.handleTickRangeOptions()}computeTickLimit(){const t=this.isHorizontal(),e=t?this.width:this.height,i=$(this.options.ticks.minRotation),s=(t?Math.sin(i):Math.cos(i))||.001,n=this._resolveTickFontOptions(0);return Math.ceil(e/Math.min(40,n.lineHeight/s))}getPixelForValue(t){return null===t?NaN:this.getPixelForDecimal((t-this._startValue)/this._valueRange)}getValueForPixel(t){return this._startValue+this.getDecimalForPixel(t)*this._valueRange}}const _o=t=>Math.floor(z(t)),yo=(t,e)=>Math.pow(10,_o(t)+e);function vo(t){return 1===t/Math.pow(10,_o(t))}function Mo(t,e,i){const s=Math.pow(10,i),n=Math.floor(t/s);return Math.ceil(e/s)-n}function wo(t,{min:e,max:i}){e=r(t.min,e);const s=[],n=_o(e);let o=function(t,e){let i=_o(e-t);for(;Mo(t,e,i)>10;)i++;for(;Mo(t,e,i)<10;)i--;return Math.min(i,_o(t))}(e,i),a=o<0?Math.pow(10,Math.abs(o)):1;const l=Math.pow(10,o),h=n>o?Math.pow(10,n):0,c=Math.round((e-h)*a)/a,d=Math.floor((e-h)/l/10)*l*10;let u=Math.floor((c-d)/Math.pow(10,o)),f=r(t.min,Math.round((h+d+u*Math.pow(10,o))*a)/a);for(;f=10?u=u<15?15:20:u++,u>=20&&(o++,u=2,a=o>=0?1:a),f=Math.round((h+d+u*Math.pow(10,o))*a)/a;const g=r(t.max,f);return s.push({value:g,major:vo(g),significand:u}),s}class ko extends Js{static id="logarithmic";static defaults={ticks:{callback:ae.formatters.logarithmic,major:{enabled:!0}}};constructor(t){super(t),this.start=void 0,this.end=void 0,this._startValue=void 0,this._valueRange=0}parse(t,e){const i=bo.prototype.parse.apply(this,[t,e]);if(0!==i)return a(i)&&i>0?i:null;this._zero=!0}determineDataLimits(){const{min:t,max:e}=this.getMinMax(!0);this.min=a(t)?Math.max(0,t):null,this.max=a(e)?Math.max(0,e):null,this.options.beginAtZero&&(this._zero=!0),this._zero&&this.min!==this._suggestedMin&&!a(this._userMin)&&(this.min=t===yo(this.min,0)?yo(this.min,-1):yo(this.min,0)),this.handleTickRangeOptions()}handleTickRangeOptions(){const{minDefined:t,maxDefined:e}=this.getUserBounds();let i=this.min,s=this.max;const n=e=>i=t?i:e,o=t=>s=e?s:t;i===s&&(i<=0?(n(1),o(10)):(n(yo(i,-1)),o(yo(s,1)))),i<=0&&n(yo(s,-1)),s<=0&&o(yo(i,1)),this.min=i,this.max=s}buildTicks(){const t=this.options,e=wo({min:this._userMin,max:this._userMax},this);return"ticks"===t.bounds&&j(e,this,"value"),t.reverse?(e.reverse(),this.start=this.max,this.end=this.min):(this.start=this.min,this.end=this.max),e}getLabelForValue(t){return void 0===t?"0":ne(t,this.chart.options.locale,this.options.ticks.format)}configure(){const t=this.min;super.configure(),this._startValue=z(t),this._valueRange=z(this.max)-z(t)}getPixelForValue(t){return void 0!==t&&0!==t||(t=this.min),null===t||isNaN(t)?NaN:this.getPixelForDecimal(t===this.min?0:(z(t)-this._startValue)/this._valueRange)}getValueForPixel(t){const e=this.getDecimalForPixel(t);return Math.pow(10,this._startValue+e*this._valueRange)}}function So(t){const e=t.ticks;if(e.display&&t.display){const t=ki(e.backdropPadding);return l(e.font&&e.font.size,ue.font.size)+t.height}return 0}function Po(t,e,i,s,n){return t===s||t===n?{start:e-i/2,end:e+i/2}:tn?{start:e-i,end:e}:{start:e,end:e+i}}function Do(t){const e={l:t.left+t._padding.left,r:t.right-t._padding.right,t:t.top+t._padding.top,b:t.bottom-t._padding.bottom},i=Object.assign({},e),s=[],o=[],a=t._pointLabels.length,r=t.options.pointLabels,l=r.centerPointLabels?C/a:0;for(let u=0;ue.r&&(r=(s.end-e.r)/o,t.r=Math.max(t.r,e.r+r)),n.starte.b&&(l=(n.end-e.b)/a,t.b=Math.max(t.b,e.b+l))}function Oo(t,e,i){const s=t.drawingArea,{extra:n,additionalAngle:o,padding:a,size:r}=i,l=t.getPointPosition(e,s+n+a,o),h=Math.round(Y(G(l.angle+E))),c=function(t,e,i){90===i||270===i?t-=e/2:(i>270||i<90)&&(t-=e);return t}(l.y,r.h,h),d=function(t){if(0===t||180===t)return"center";if(t<180)return"left";return"right"}(h),u=function(t,e,i){"right"===i?t-=e:"center"===i&&(t-=e/2);return t}(l.x,r.w,d);return{visible:!0,x:l.x,y:c,textAlign:d,left:u,top:c,right:u+r.w,bottom:c+r.h}}function Ao(t,e){if(!e)return!0;const{left:i,top:s,right:n,bottom:o}=t;return!(Re({x:i,y:s},e)||Re({x:i,y:o},e)||Re({x:n,y:s},e)||Re({x:n,y:o},e))}function To(t,e,i){const{left:n,top:o,right:a,bottom:r}=i,{backdropColor:l}=e;if(!s(l)){const i=wi(e.borderRadius),s=ki(e.backdropPadding);t.fillStyle=l;const h=n-s.left,c=o-s.top,d=a-n+s.width,u=r-o+s.height;Object.values(i).some((t=>0!==t))?(t.beginPath(),He(t,{x:h,y:c,w:d,h:u,radius:i}),t.fill()):t.fillRect(h,c,d,u)}}function Lo(t,e,i,s){const{ctx:n}=t;if(i)n.arc(t.xCenter,t.yCenter,e,0,O);else{let i=t.getPointPosition(0,e);n.moveTo(i.x,i.y);for(let o=1;ot,padding:5,centerPointLabels:!1}};static defaultRoutes={"angleLines.color":"borderColor","pointLabels.color":"color","ticks.color":"color"};static descriptors={angleLines:{_fallback:"grid"}};constructor(t){super(t),this.xCenter=void 0,this.yCenter=void 0,this.drawingArea=void 0,this._pointLabels=[],this._pointLabelItems=[]}setDimensions(){const t=this._padding=ki(So(this.options)/2),e=this.width=this.maxWidth-t.width,i=this.height=this.maxHeight-t.height;this.xCenter=Math.floor(this.left+e/2+t.left),this.yCenter=Math.floor(this.top+i/2+t.top),this.drawingArea=Math.floor(Math.min(e,i)/2)}determineDataLimits(){const{min:t,max:e}=this.getMinMax(!1);this.min=a(t)&&!isNaN(t)?t:0,this.max=a(e)&&!isNaN(e)?e:0,this.handleTickRangeOptions()}computeTickLimit(){return Math.ceil(this.drawingArea/So(this.options))}generateTickLabels(t){bo.prototype.generateTickLabels.call(this,t),this._pointLabels=this.getLabels().map(((t,e)=>{const i=d(this.options.pointLabels.callback,[t,e],this);return i||0===i?i:""})).filter(((t,e)=>this.chart.getDataVisibility(e)))}fit(){const t=this.options;t.display&&t.pointLabels.display?Do(this):this.setCenterPoint(0,0,0,0)}setCenterPoint(t,e,i,s){this.xCenter+=Math.floor((t-e)/2),this.yCenter+=Math.floor((i-s)/2),this.drawingArea-=Math.min(this.drawingArea/2,Math.max(t,e,i,s))}getIndexAngle(t){return G(t*(O/(this._pointLabels.length||1))+$(this.options.startAngle||0))}getDistanceFromCenterForValue(t){if(s(t))return NaN;const e=this.drawingArea/(this.max-this.min);return this.options.reverse?(this.max-t)*e:(t-this.min)*e}getValueForDistanceFromCenter(t){if(s(t))return NaN;const e=t/(this.drawingArea/(this.max-this.min));return this.options.reverse?this.max-e:this.min+e}getPointLabelContext(t){const e=this._pointLabels||[];if(t>=0&&t=0;n--){const e=t._pointLabelItems[n];if(!e.visible)continue;const o=s.setContext(t.getPointLabelContext(n));To(i,o,e);const a=Si(o.font),{x:r,y:l,textAlign:h}=e;Ne(i,t._pointLabels[n],r,l+a.lineHeight/2,a,{color:o.color,textAlign:h,textBaseline:"middle"})}}(this,o),s.display&&this.ticks.forEach(((t,e)=>{if(0!==e||0===e&&this.min<0){r=this.getDistanceFromCenterForValue(t.value);const i=this.getContext(e),a=s.setContext(i),l=n.setContext(i);!function(t,e,i,s,n){const o=t.ctx,a=e.circular,{color:r,lineWidth:l}=e;!a&&!s||!r||!l||i<0||(o.save(),o.strokeStyle=r,o.lineWidth=l,o.setLineDash(n.dash),o.lineDashOffset=n.dashOffset,o.beginPath(),Lo(t,i,a,s),o.closePath(),o.stroke(),o.restore())}(this,a,r,o,l)}})),i.display){for(t.save(),a=o-1;a>=0;a--){const s=i.setContext(this.getPointLabelContext(a)),{color:n,lineWidth:o}=s;o&&n&&(t.lineWidth=o,t.strokeStyle=n,t.setLineDash(s.borderDash),t.lineDashOffset=s.borderDashOffset,r=this.getDistanceFromCenterForValue(e.ticks.reverse?this.min:this.max),l=this.getPointPosition(a,r),t.beginPath(),t.moveTo(this.xCenter,this.yCenter),t.lineTo(l.x,l.y),t.stroke())}t.restore()}}drawBorder(){}drawLabels(){const t=this.ctx,e=this.options,i=e.ticks;if(!i.display)return;const s=this.getIndexAngle(0);let n,o;t.save(),t.translate(this.xCenter,this.yCenter),t.rotate(s),t.textAlign="center",t.textBaseline="middle",this.ticks.forEach(((s,a)=>{if(0===a&&this.min>=0&&!e.reverse)return;const r=i.setContext(this.getContext(a)),l=Si(r.font);if(n=this.getDistanceFromCenterForValue(this.ticks[a].value),r.showLabelBackdrop){t.font=l.string,o=t.measureText(s.label).width,t.fillStyle=r.backdropColor;const e=ki(r.backdropPadding);t.fillRect(-o/2-e.left,-n-l.size/2-e.top,o+e.width,l.size+e.height)}Ne(t,s.label,0,-n,l,{color:r.color,strokeColor:r.textStrokeColor,strokeWidth:r.textStrokeWidth})})),t.restore()}drawTitle(){}}const Ro={millisecond:{common:!0,size:1,steps:1e3},second:{common:!0,size:1e3,steps:60},minute:{common:!0,size:6e4,steps:60},hour:{common:!0,size:36e5,steps:24},day:{common:!0,size:864e5,steps:30},week:{common:!1,size:6048e5,steps:4},month:{common:!0,size:2628e6,steps:12},quarter:{common:!1,size:7884e6,steps:4},year:{common:!0,size:3154e7}},Io=Object.keys(Ro);function zo(t,e){return t-e}function Fo(t,e){if(s(e))return null;const i=t._adapter,{parser:n,round:o,isoWeekday:r}=t._parseOpts;let l=e;return"function"==typeof n&&(l=n(l)),a(l)||(l="string"==typeof n?i.parse(l,n):i.parse(l)),null===l?null:(o&&(l="week"!==o||!N(r)&&!0!==r?i.startOf(l,o):i.startOf(l,"isoWeek",r)),+l)}function Vo(t,e,i,s){const n=Io.length;for(let o=Io.indexOf(t);o=e?i[s]:i[n]]=!0}}else t[e]=!0}function Wo(t,e,i){const s=[],n={},o=e.length;let a,r;for(a=0;a=0&&(e[l].major=!0);return e}(t,s,n,i):s}class No extends Js{static id="time";static defaults={bounds:"data",adapters:{},time:{parser:!1,unit:!1,round:!1,isoWeekday:!1,minUnit:"millisecond",displayFormats:{}},ticks:{source:"auto",callback:!1,major:{enabled:!1}}};constructor(t){super(t),this._cache={data:[],labels:[],all:[]},this._unit="day",this._majorUnit=void 0,this._offsets={},this._normalized=!1,this._parseOpts=void 0}init(t,e={}){const i=t.time||(t.time={}),s=this._adapter=new Rn._date(t.adapters.date);s.init(e),x(i.displayFormats,s.formats()),this._parseOpts={parser:i.parser,round:i.round,isoWeekday:i.isoWeekday},super.init(t),this._normalized=e.normalized}parse(t,e){return void 0===t?null:Fo(this,t)}beforeLayout(){super.beforeLayout(),this._cache={data:[],labels:[],all:[]}}determineDataLimits(){const t=this.options,e=this._adapter,i=t.time.unit||"day";let{min:s,max:n,minDefined:o,maxDefined:r}=this.getUserBounds();function l(t){o||isNaN(t.min)||(s=Math.min(s,t.min)),r||isNaN(t.max)||(n=Math.max(n,t.max))}o&&r||(l(this._getLabelBounds()),"ticks"===t.bounds&&"labels"===t.ticks.source||l(this.getMinMax(!1))),s=a(s)&&!isNaN(s)?s:+e.startOf(Date.now(),i),n=a(n)&&!isNaN(n)?n:+e.endOf(Date.now(),i)+1,this.min=Math.min(s,n-1),this.max=Math.max(s+1,n)}_getLabelBounds(){const t=this.getLabelTimestamps();let e=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY;return t.length&&(e=t[0],i=t[t.length-1]),{min:e,max:i}}buildTicks(){const t=this.options,e=t.time,i=t.ticks,s="labels"===i.source?this.getLabelTimestamps():this._generate();"ticks"===t.bounds&&s.length&&(this.min=this._userMin||s[0],this.max=this._userMax||s[s.length-1]);const n=this.min,o=nt(s,n,this.max);return this._unit=e.unit||(i.autoSkip?Vo(e.minUnit,this.min,this.max,this._getLabelCapacity(n)):function(t,e,i,s,n){for(let o=Io.length-1;o>=Io.indexOf(i);o--){const i=Io[o];if(Ro[i].common&&t._adapter.diff(n,s,i)>=e-1)return i}return Io[i?Io.indexOf(i):0]}(this,o.length,e.minUnit,this.min,this.max)),this._majorUnit=i.major.enabled&&"year"!==this._unit?function(t){for(let e=Io.indexOf(t)+1,i=Io.length;e+t.value)))}initOffsets(t=[]){let e,i,s=0,n=0;this.options.offset&&t.length&&(e=this.getDecimalForValue(t[0]),s=1===t.length?1-e:(this.getDecimalForValue(t[1])-e)/2,i=this.getDecimalForValue(t[t.length-1]),n=1===t.length?i:(i-this.getDecimalForValue(t[t.length-2]))/2);const o=t.length<3?.5:.25;s=J(s,0,o),n=J(n,0,o),this._offsets={start:s,end:n,factor:1/(s+1+n)}}_generate(){const t=this._adapter,e=this.min,i=this.max,s=this.options,n=s.time,o=n.unit||Vo(n.minUnit,e,i,this._getLabelCapacity(e)),a=l(s.ticks.stepSize,1),r="week"===o&&n.isoWeekday,h=N(r)||!0===r,c={};let d,u,f=e;if(h&&(f=+t.startOf(f,"isoWeek",r)),f=+t.startOf(f,h?"day":o),t.diff(i,e,o)>1e5*a)throw new Error(e+" and "+i+" are too far apart with stepSize of "+a+" "+o);const g="data"===s.ticks.source&&this.getDataTimestamps();for(d=f,u=0;d+t))}getLabelForValue(t){const e=this._adapter,i=this.options.time;return i.tooltipFormat?e.format(t,i.tooltipFormat):e.format(t,i.displayFormats.datetime)}format(t,e){const i=this.options.time.displayFormats,s=this._unit,n=e||i[s];return this._adapter.format(t,n)}_tickFormatFunction(t,e,i,s){const n=this.options,o=n.ticks.callback;if(o)return d(o,[t,e,i],this);const a=n.time.displayFormats,r=this._unit,l=this._majorUnit,h=r&&a[r],c=l&&a[l],u=i[e],f=l&&c&&u&&u.major;return this._adapter.format(t,s||(f?c:h))}generateTickLabels(t){let e,i,s;for(e=0,i=t.length;e0?a:1}getDataTimestamps(){let t,e,i=this._cache.data||[];if(i.length)return i;const s=this.getMatchingVisibleMetas();if(this._normalized&&s.length)return this._cache.data=s[0].controller.getAllParsedValues(this);for(t=0,e=s.length;t=t[r].pos&&e<=t[l].pos&&({lo:r,hi:l}=it(t,"pos",e)),({pos:s,time:o}=t[r]),({pos:n,time:a}=t[l])):(e>=t[r].time&&e<=t[l].time&&({lo:r,hi:l}=it(t,"time",e)),({time:s,pos:o}=t[r]),({time:n,pos:a}=t[l]));const h=n-s;return h?o+(a-o)*(e-s)/h:o}var jo=Object.freeze({__proto__:null,CategoryScale:class extends Js{static id="category";static defaults={ticks:{callback:po}};constructor(t){super(t),this._startValue=void 0,this._valueRange=0,this._addedLabels=[]}init(t){const e=this._addedLabels;if(e.length){const t=this.getLabels();for(const{index:i,label:s}of e)t[i]===s&&t.splice(i,1);this._addedLabels=[]}super.init(t)}parse(t,e){if(s(t))return null;const i=this.getLabels();return((t,e)=>null===t?null:J(Math.round(t),0,e))(e=isFinite(e)&&i[e]===t?e:go(i,t,l(e,t),this._addedLabels),i.length-1)}determineDataLimits(){const{minDefined:t,maxDefined:e}=this.getUserBounds();let{min:i,max:s}=this.getMinMax(!0);"ticks"===this.options.bounds&&(t||(i=0),e||(s=this.getLabels().length-1)),this.min=i,this.max=s}buildTicks(){const t=this.min,e=this.max,i=this.options.offset,s=[];let n=this.getLabels();n=0===t&&e===n.length-1?n:n.slice(t,e+1),this._valueRange=Math.max(n.length-(i?0:1),1),this._startValue=this.min-(i?.5:0);for(let i=t;i<=e;i++)s.push({value:i});return s}getLabelForValue(t){return po.call(this,t)}configure(){super.configure(),this.isHorizontal()||(this._reversePixels=!this._reversePixels)}getPixelForValue(t){return"number"!=typeof t&&(t=this.parse(t)),null===t?NaN:this.getPixelForDecimal((t-this._startValue)/this._valueRange)}getPixelForTick(t){const e=this.ticks;return t<0||t>e.length-1?null:this.getPixelForValue(e[t].value)}getValueForPixel(t){return Math.round(this._startValue+this.getDecimalForPixel(t)*this._valueRange)}getBasePixel(){return this.bottom}},LinearScale:xo,LogarithmicScale:ko,RadialLinearScale:Eo,TimeScale:No,TimeSeriesScale:class extends No{static id="timeseries";static defaults=No.defaults;constructor(t){super(t),this._table=[],this._minPos=void 0,this._tableRange=void 0}initOffsets(){const t=this._getTimestampsForTable(),e=this._table=this.buildLookupTable(t);this._minPos=Ho(e,this.min),this._tableRange=Ho(e,this.max)-this._minPos,super.initOffsets(t)}buildLookupTable(t){const{min:e,max:i}=this,s=[],n=[];let o,a,r,l,h;for(o=0,a=t.length;o=e&&l<=i&&s.push(l);if(s.length<2)return[{time:e,pos:0},{time:i,pos:1}];for(o=0,a=s.length;ot-e))}_getTimestampsForTable(){let t=this._cache.all||[];if(t.length)return t;const e=this.getDataTimestamps(),i=this.getLabelTimestamps();return t=e.length&&i.length?this.normalize(e.concat(i)):e.length?e:i,t=this._cache.all=t,t}getDecimalForValue(t){return(Ho(this._table,t)-this._minPos)/this._tableRange}getValueForPixel(t){const e=this._offsets,i=this.getDecimalForPixel(t)/e.factor-e.end;return Ho(this._table,i*this._tableRange+this._minPos,!0)}}});const $o=["rgb(54, 162, 235)","rgb(255, 99, 132)","rgb(255, 159, 64)","rgb(255, 205, 86)","rgb(75, 192, 192)","rgb(153, 102, 255)","rgb(201, 203, 207)"],Yo=$o.map((t=>t.replace("rgb(","rgba(").replace(")",", 0.5)")));function Uo(t){return $o[t%$o.length]}function Xo(t){return Yo[t%Yo.length]}function qo(t){let e=0;return(i,s)=>{const n=t.getDatasetMeta(s).controller;n instanceof jn?e=function(t,e){return t.backgroundColor=t.data.map((()=>Uo(e++))),e}(i,e):n instanceof $n?e=function(t,e){return t.backgroundColor=t.data.map((()=>Xo(e++))),e}(i,e):n&&(e=function(t,e){return t.borderColor=Uo(e),t.backgroundColor=Xo(e),++e}(i,e))}}function Ko(t){let e;for(e in t)if(t[e].borderColor||t[e].backgroundColor)return!0;return!1}var Go={id:"colors",defaults:{enabled:!0,forceOverride:!1},beforeLayout(t,e,i){if(!i.enabled)return;const{data:{datasets:s},options:n}=t.config,{elements:o}=n;if(!i.forceOverride&&(Ko(s)||(a=n)&&(a.borderColor||a.backgroundColor)||o&&Ko(o)))return;var a;const r=qo(t);s.forEach(r)}};function Zo(t){if(t._decimated){const e=t._data;delete t._decimated,delete t._data,Object.defineProperty(t,"data",{configurable:!0,enumerable:!0,writable:!0,value:e})}}function Jo(t){t.data.datasets.forEach((t=>{Zo(t)}))}var Qo={id:"decimation",defaults:{algorithm:"min-max",enabled:!1},beforeElementsUpdate:(t,e,i)=>{if(!i.enabled)return void Jo(t);const n=t.width;t.data.datasets.forEach(((e,o)=>{const{_data:a,indexAxis:r}=e,l=t.getDatasetMeta(o),h=a||e.data;if("y"===Pi([r,t.options.indexAxis]))return;if(!l.controller.supportsDecimation)return;const c=t.scales[l.xAxisID];if("linear"!==c.type&&"time"!==c.type)return;if(t.options.parsing)return;let{start:d,count:u}=function(t,e){const i=e.length;let s,n=0;const{iScale:o}=t,{min:a,max:r,minDefined:l,maxDefined:h}=o.getUserBounds();return l&&(n=J(it(e,o.axis,a).lo,0,i-1)),s=h?J(it(e,o.axis,r).hi+1,n,i)-n:i-n,{start:n,count:s}}(l,h);if(u<=(i.threshold||4*n))return void Zo(e);let f;switch(s(a)&&(e._data=h,delete e.data,Object.defineProperty(e,"data",{configurable:!0,enumerable:!0,get:function(){return this._decimated},set:function(t){this._data=t}})),i.algorithm){case"lttb":f=function(t,e,i,s,n){const o=n.samples||s;if(o>=i)return t.slice(e,e+i);const a=[],r=(i-2)/(o-2);let l=0;const h=e+i-1;let c,d,u,f,g,p=e;for(a[l++]=t[p],c=0;cu&&(u=f,d=t[s],g=s);a[l++]=d,p=g}return a[l++]=t[h],a}(h,d,u,n,i);break;case"min-max":f=function(t,e,i,n){let o,a,r,l,h,c,d,u,f,g,p=0,m=0;const b=[],x=e+i-1,_=t[e].x,y=t[x].x-_;for(o=e;og&&(g=l,d=o),p=(m*p+a.x)/++m;else{const i=o-1;if(!s(c)&&!s(d)){const e=Math.min(c,d),s=Math.max(c,d);e!==u&&e!==i&&b.push({...t[e],x:p}),s!==u&&s!==i&&b.push({...t[s],x:p})}o>0&&i!==u&&b.push(t[i]),b.push(a),h=e,m=0,f=g=l,c=d=u=o}}return b}(h,d,u,n);break;default:throw new Error(`Unsupported decimation algorithm '${i.algorithm}'`)}e._decimated=f}))},destroy(t){Jo(t)}};function ta(t,e,i,s){if(s)return;let n=e[t],o=i[t];return"angle"===t&&(n=G(n),o=G(o)),{property:t,start:n,end:o}}function ea(t,e,i){for(;e>t;e--){const t=i[e];if(!isNaN(t.x)&&!isNaN(t.y))break}return e}function ia(t,e,i,s){return t&&e?s(t[i],e[i]):t?t[i]:e?e[i]:0}function sa(t,e){let i=[],s=!1;return n(t)?(s=!0,i=t):i=function(t,e){const{x:i=null,y:s=null}=t||{},n=e.points,o=[];return e.segments.forEach((({start:t,end:e})=>{e=ea(t,e,n);const a=n[t],r=n[e];null!==s?(o.push({x:a.x,y:s}),o.push({x:r.x,y:s})):null!==i&&(o.push({x:i,y:a.y}),o.push({x:i,y:r.y}))})),o}(t,e),i.length?new no({points:i,options:{tension:0},_loop:s,_fullLoop:s}):null}function na(t){return t&&!1!==t.fill}function oa(t,e,i){let s=t[e].fill;const n=[e];let o;if(!i)return s;for(;!1!==s&&-1===n.indexOf(s);){if(!a(s))return s;if(o=t[s],!o)return!1;if(o.visible)return s;n.push(s),s=o.fill}return!1}function aa(t,e,i){const s=function(t){const e=t.options,i=e.fill;let s=l(i&&i.target,i);void 0===s&&(s=!!e.backgroundColor);if(!1===s||null===s)return!1;if(!0===s)return"origin";return s}(t);if(o(s))return!isNaN(s.value)&&s;let n=parseFloat(s);return a(n)&&Math.floor(n)===n?function(t,e,i,s){"-"!==t&&"+"!==t||(i=e+i);if(i===e||i<0||i>=s)return!1;return i}(s[0],e,n,i):["origin","start","end","stack","shape"].indexOf(s)>=0&&s}function ra(t,e,i){const s=[];for(let n=0;n=0;--e){const i=n[e].$filler;i&&(i.line.updateControlPoints(o,i.axis),s&&i.fill&&da(t.ctx,i,o))}},beforeDatasetsDraw(t,e,i){if("beforeDatasetsDraw"!==i.drawTime)return;const s=t.getSortedVisibleDatasetMetas();for(let e=s.length-1;e>=0;--e){const i=s[e].$filler;na(i)&&da(t.ctx,i,t.chartArea)}},beforeDatasetDraw(t,e,i){const s=e.meta.$filler;na(s)&&"beforeDatasetDraw"===i.drawTime&&da(t.ctx,s,t.chartArea)},defaults:{propagate:!0,drawTime:"beforeDatasetDraw"}};const ba=(t,e)=>{let{boxHeight:i=e,boxWidth:s=e}=t;return t.usePointStyle&&(i=Math.min(i,e),s=t.pointStyleWidth||Math.min(s,e)),{boxWidth:s,boxHeight:i,itemHeight:Math.max(e,i)}};class xa extends Hs{constructor(t){super(),this._added=!1,this.legendHitBoxes=[],this._hoveredItem=null,this.doughnutMode=!1,this.chart=t.chart,this.options=t.options,this.ctx=t.ctx,this.legendItems=void 0,this.columnSizes=void 0,this.lineWidths=void 0,this.maxHeight=void 0,this.maxWidth=void 0,this.top=void 0,this.bottom=void 0,this.left=void 0,this.right=void 0,this.height=void 0,this.width=void 0,this._margins=void 0,this.position=void 0,this.weight=void 0,this.fullSize=void 0}update(t,e,i){this.maxWidth=t,this.maxHeight=e,this._margins=i,this.setDimensions(),this.buildLabels(),this.fit()}setDimensions(){this.isHorizontal()?(this.width=this.maxWidth,this.left=this._margins.left,this.right=this.width):(this.height=this.maxHeight,this.top=this._margins.top,this.bottom=this.height)}buildLabels(){const t=this.options.labels||{};let e=d(t.generateLabels,[this.chart],this)||[];t.filter&&(e=e.filter((e=>t.filter(e,this.chart.data)))),t.sort&&(e=e.sort(((e,i)=>t.sort(e,i,this.chart.data)))),this.options.reverse&&e.reverse(),this.legendItems=e}fit(){const{options:t,ctx:e}=this;if(!t.display)return void(this.width=this.height=0);const i=t.labels,s=Si(i.font),n=s.size,o=this._computeTitleHeight(),{boxWidth:a,itemHeight:r}=ba(i,n);let l,h;e.font=s.string,this.isHorizontal()?(l=this.maxWidth,h=this._fitRows(o,n,a,r)+10):(h=this.maxHeight,l=this._fitCols(o,s,a,r)+10),this.width=Math.min(l,t.maxWidth||this.maxWidth),this.height=Math.min(h,t.maxHeight||this.maxHeight)}_fitRows(t,e,i,s){const{ctx:n,maxWidth:o,options:{labels:{padding:a}}}=this,r=this.legendHitBoxes=[],l=this.lineWidths=[0],h=s+a;let c=t;n.textAlign="left",n.textBaseline="middle";let d=-1,u=-h;return this.legendItems.forEach(((t,f)=>{const g=i+e/2+n.measureText(t.text).width;(0===f||l[l.length-1]+g+2*a>o)&&(c+=h,l[l.length-(f>0?0:1)]=0,u+=h,d++),r[f]={left:0,top:u,row:d,width:g,height:s},l[l.length-1]+=g+a})),c}_fitCols(t,e,i,s){const{ctx:n,maxHeight:o,options:{labels:{padding:a}}}=this,r=this.legendHitBoxes=[],l=this.columnSizes=[],h=o-t;let c=a,d=0,u=0,f=0,g=0;return this.legendItems.forEach(((t,o)=>{const{itemWidth:p,itemHeight:m}=function(t,e,i,s,n){const o=function(t,e,i,s){let n=t.text;n&&"string"!=typeof n&&(n=n.reduce(((t,e)=>t.length>e.length?t:e)));return e+i.size/2+s.measureText(n).width}(s,t,e,i),a=function(t,e,i){let s=t;"string"!=typeof e.text&&(s=_a(e,i));return s}(n,s,e.lineHeight);return{itemWidth:o,itemHeight:a}}(i,e,n,t,s);o>0&&u+m+2*a>h&&(c+=d+a,l.push({width:d,height:u}),f+=d+a,g++,d=u=0),r[o]={left:f,top:u,col:g,width:p,height:m},d=Math.max(d,p),u+=m+a})),c+=d,l.push({width:d,height:u}),c}adjustHitBoxes(){if(!this.options.display)return;const t=this._computeTitleHeight(),{legendHitBoxes:e,options:{align:i,labels:{padding:s},rtl:n}}=this,o=Oi(n,this.left,this.width);if(this.isHorizontal()){let n=0,a=ft(i,this.left+s,this.right-this.lineWidths[n]);for(const r of e)n!==r.row&&(n=r.row,a=ft(i,this.left+s,this.right-this.lineWidths[n])),r.top+=this.top+t+s,r.left=o.leftForLtr(o.x(a),r.width),a+=r.width+s}else{let n=0,a=ft(i,this.top+t+s,this.bottom-this.columnSizes[n].height);for(const r of e)r.col!==n&&(n=r.col,a=ft(i,this.top+t+s,this.bottom-this.columnSizes[n].height)),r.top=a,r.left+=this.left+s,r.left=o.leftForLtr(o.x(r.left),r.width),a+=r.height+s}}isHorizontal(){return"top"===this.options.position||"bottom"===this.options.position}draw(){if(this.options.display){const t=this.ctx;Ie(t,this),this._draw(),ze(t)}}_draw(){const{options:t,columnSizes:e,lineWidths:i,ctx:s}=this,{align:n,labels:o}=t,a=ue.color,r=Oi(t.rtl,this.left,this.width),h=Si(o.font),{padding:c}=o,d=h.size,u=d/2;let f;this.drawTitle(),s.textAlign=r.textAlign("left"),s.textBaseline="middle",s.lineWidth=.5,s.font=h.string;const{boxWidth:g,boxHeight:p,itemHeight:m}=ba(o,d),b=this.isHorizontal(),x=this._computeTitleHeight();f=b?{x:ft(n,this.left+c,this.right-i[0]),y:this.top+c+x,line:0}:{x:this.left+c,y:ft(n,this.top+x+c,this.bottom-e[0].height),line:0},Ai(this.ctx,t.textDirection);const _=m+c;this.legendItems.forEach(((y,v)=>{s.strokeStyle=y.fontColor,s.fillStyle=y.fontColor;const M=s.measureText(y.text).width,w=r.textAlign(y.textAlign||(y.textAlign=o.textAlign)),k=g+u+M;let S=f.x,P=f.y;r.setWidth(this.width),b?v>0&&S+k+c>this.right&&(P=f.y+=_,f.line++,S=f.x=ft(n,this.left+c,this.right-i[f.line])):v>0&&P+_>this.bottom&&(S=f.x=S+e[f.line].width+c,f.line++,P=f.y=ft(n,this.top+x+c,this.bottom-e[f.line].height));if(function(t,e,i){if(isNaN(g)||g<=0||isNaN(p)||p<0)return;s.save();const n=l(i.lineWidth,1);if(s.fillStyle=l(i.fillStyle,a),s.lineCap=l(i.lineCap,"butt"),s.lineDashOffset=l(i.lineDashOffset,0),s.lineJoin=l(i.lineJoin,"miter"),s.lineWidth=n,s.strokeStyle=l(i.strokeStyle,a),s.setLineDash(l(i.lineDash,[])),o.usePointStyle){const a={radius:p*Math.SQRT2/2,pointStyle:i.pointStyle,rotation:i.rotation,borderWidth:n},l=r.xPlus(t,g/2);Ee(s,a,l,e+u,o.pointStyleWidth&&g)}else{const o=e+Math.max((d-p)/2,0),a=r.leftForLtr(t,g),l=wi(i.borderRadius);s.beginPath(),Object.values(l).some((t=>0!==t))?He(s,{x:a,y:o,w:g,h:p,radius:l}):s.rect(a,o,g,p),s.fill(),0!==n&&s.stroke()}s.restore()}(r.x(S),P,y),S=gt(w,S+g+u,b?S+k:this.right,t.rtl),function(t,e,i){Ne(s,i.text,t,e+m/2,h,{strikethrough:i.hidden,textAlign:r.textAlign(i.textAlign)})}(r.x(S),P,y),b)f.x+=k+c;else if("string"!=typeof y.text){const t=h.lineHeight;f.y+=_a(y,t)+c}else f.y+=_})),Ti(this.ctx,t.textDirection)}drawTitle(){const t=this.options,e=t.title,i=Si(e.font),s=ki(e.padding);if(!e.display)return;const n=Oi(t.rtl,this.left,this.width),o=this.ctx,a=e.position,r=i.size/2,l=s.top+r;let h,c=this.left,d=this.width;if(this.isHorizontal())d=Math.max(...this.lineWidths),h=this.top+l,c=ft(t.align,c,this.right-d);else{const e=this.columnSizes.reduce(((t,e)=>Math.max(t,e.height)),0);h=l+ft(t.align,this.top,this.bottom-e-t.labels.padding-this._computeTitleHeight())}const u=ft(a,c,c+d);o.textAlign=n.textAlign(ut(a)),o.textBaseline="middle",o.strokeStyle=e.color,o.fillStyle=e.color,o.font=i.string,Ne(o,e.text,u,h,i)}_computeTitleHeight(){const t=this.options.title,e=Si(t.font),i=ki(t.padding);return t.display?e.lineHeight+i.height:0}_getLegendItemAt(t,e){let i,s,n;if(tt(t,this.left,this.right)&&tt(e,this.top,this.bottom))for(n=this.legendHitBoxes,i=0;it.chart.options.color,boxWidth:40,padding:10,generateLabels(t){const e=t.data.datasets,{labels:{usePointStyle:i,pointStyle:s,textAlign:n,color:o,useBorderRadius:a,borderRadius:r}}=t.legend.options;return t._getSortedDatasetMetas().map((t=>{const l=t.controller.getStyle(i?0:void 0),h=ki(l.borderWidth);return{text:e[t.index].label,fillStyle:l.backgroundColor,fontColor:o,hidden:!t.visible,lineCap:l.borderCapStyle,lineDash:l.borderDash,lineDashOffset:l.borderDashOffset,lineJoin:l.borderJoinStyle,lineWidth:(h.width+h.height)/4,strokeStyle:l.borderColor,pointStyle:s||l.pointStyle,rotation:l.rotation,textAlign:n||l.textAlign,borderRadius:a&&(r||l.borderRadius),datasetIndex:t.index}}),this)}},title:{color:t=>t.chart.options.color,display:!1,position:"center",text:""}},descriptors:{_scriptable:t=>!t.startsWith("on"),labels:{_scriptable:t=>!["generateLabels","filter","sort"].includes(t)}}};class va extends Hs{constructor(t){super(),this.chart=t.chart,this.options=t.options,this.ctx=t.ctx,this._padding=void 0,this.top=void 0,this.bottom=void 0,this.left=void 0,this.right=void 0,this.width=void 0,this.height=void 0,this.position=void 0,this.weight=void 0,this.fullSize=void 0}update(t,e){const i=this.options;if(this.left=0,this.top=0,!i.display)return void(this.width=this.height=this.right=this.bottom=0);this.width=this.right=t,this.height=this.bottom=e;const s=n(i.text)?i.text.length:1;this._padding=ki(i.padding);const o=s*Si(i.font).lineHeight+this._padding.height;this.isHorizontal()?this.height=o:this.width=o}isHorizontal(){const t=this.options.position;return"top"===t||"bottom"===t}_drawArgs(t){const{top:e,left:i,bottom:s,right:n,options:o}=this,a=o.align;let r,l,h,c=0;return this.isHorizontal()?(l=ft(a,i,n),h=e+t,r=n-i):("left"===o.position?(l=i+t,h=ft(a,s,e),c=-.5*C):(l=n-t,h=ft(a,e,s),c=.5*C),r=s-e),{titleX:l,titleY:h,maxWidth:r,rotation:c}}draw(){const t=this.ctx,e=this.options;if(!e.display)return;const i=Si(e.font),s=i.lineHeight/2+this._padding.top,{titleX:n,titleY:o,maxWidth:a,rotation:r}=this._drawArgs(s);Ne(t,e.text,0,0,i,{color:e.color,maxWidth:a,rotation:r,textAlign:ut(e.align),textBaseline:"middle",translation:[n,o]})}}var Ma={id:"title",_element:va,start(t,e,i){!function(t,e){const i=new va({ctx:t.ctx,options:e,chart:t});as.configure(t,i,e),as.addBox(t,i),t.titleBlock=i}(t,i)},stop(t){const e=t.titleBlock;as.removeBox(t,e),delete t.titleBlock},beforeUpdate(t,e,i){const s=t.titleBlock;as.configure(t,s,i),s.options=i},defaults:{align:"center",display:!1,font:{weight:"bold"},fullSize:!0,padding:10,position:"top",text:"",weight:2e3},defaultRoutes:{color:"color"},descriptors:{_scriptable:!0,_indexable:!1}};const wa=new WeakMap;var ka={id:"subtitle",start(t,e,i){const s=new va({ctx:t.ctx,options:i,chart:t});as.configure(t,s,i),as.addBox(t,s),wa.set(t,s)},stop(t){as.removeBox(t,wa.get(t)),wa.delete(t)},beforeUpdate(t,e,i){const s=wa.get(t);as.configure(t,s,i),s.options=i},defaults:{align:"center",display:!1,font:{weight:"normal"},fullSize:!0,padding:0,position:"top",text:"",weight:1500},defaultRoutes:{color:"color"},descriptors:{_scriptable:!0,_indexable:!1}};const Sa={average(t){if(!t.length)return!1;let e,i,s=new Set,n=0,o=0;for(e=0,i=t.length;et+e))/s.size,y:n/o}},nearest(t,e){if(!t.length)return!1;let i,s,n,o=e.x,a=e.y,r=Number.POSITIVE_INFINITY;for(i=0,s=t.length;i-1?t.split("\n"):t}function Ca(t,e){const{element:i,datasetIndex:s,index:n}=e,o=t.getDatasetMeta(s).controller,{label:a,value:r}=o.getLabelAndValue(n);return{chart:t,label:a,parsed:o.getParsed(n),raw:t.data.datasets[s].data[n],formattedValue:r,dataset:o.getDataset(),dataIndex:n,datasetIndex:s,element:i}}function Oa(t,e){const i=t.chart.ctx,{body:s,footer:n,title:o}=t,{boxWidth:a,boxHeight:r}=e,l=Si(e.bodyFont),h=Si(e.titleFont),c=Si(e.footerFont),d=o.length,f=n.length,g=s.length,p=ki(e.padding);let m=p.height,b=0,x=s.reduce(((t,e)=>t+e.before.length+e.lines.length+e.after.length),0);if(x+=t.beforeBody.length+t.afterBody.length,d&&(m+=d*h.lineHeight+(d-1)*e.titleSpacing+e.titleMarginBottom),x){m+=g*(e.displayColors?Math.max(r,l.lineHeight):l.lineHeight)+(x-g)*l.lineHeight+(x-1)*e.bodySpacing}f&&(m+=e.footerMarginTop+f*c.lineHeight+(f-1)*e.footerSpacing);let _=0;const y=function(t){b=Math.max(b,i.measureText(t).width+_)};return i.save(),i.font=h.string,u(t.title,y),i.font=l.string,u(t.beforeBody.concat(t.afterBody),y),_=e.displayColors?a+2+e.boxPadding:0,u(s,(t=>{u(t.before,y),u(t.lines,y),u(t.after,y)})),_=0,i.font=c.string,u(t.footer,y),i.restore(),b+=p.width,{width:b,height:m}}function Aa(t,e,i,s){const{x:n,width:o}=i,{width:a,chartArea:{left:r,right:l}}=t;let h="center";return"center"===s?h=n<=(r+l)/2?"left":"right":n<=o/2?h="left":n>=a-o/2&&(h="right"),function(t,e,i,s){const{x:n,width:o}=s,a=i.caretSize+i.caretPadding;return"left"===t&&n+o+a>e.width||"right"===t&&n-o-a<0||void 0}(h,t,e,i)&&(h="center"),h}function Ta(t,e,i){const s=i.yAlign||e.yAlign||function(t,e){const{y:i,height:s}=e;return it.height-s/2?"bottom":"center"}(t,i);return{xAlign:i.xAlign||e.xAlign||Aa(t,e,i,s),yAlign:s}}function La(t,e,i,s){const{caretSize:n,caretPadding:o,cornerRadius:a}=t,{xAlign:r,yAlign:l}=i,h=n+o,{topLeft:c,topRight:d,bottomLeft:u,bottomRight:f}=wi(a);let g=function(t,e){let{x:i,width:s}=t;return"right"===e?i-=s:"center"===e&&(i-=s/2),i}(e,r);const p=function(t,e,i){let{y:s,height:n}=t;return"top"===e?s+=i:s-="bottom"===e?n+i:n/2,s}(e,l,h);return"center"===l?"left"===r?g+=h:"right"===r&&(g-=h):"left"===r?g-=Math.max(c,u)+n:"right"===r&&(g+=Math.max(d,f)+n),{x:J(g,0,s.width-e.width),y:J(p,0,s.height-e.height)}}function Ea(t,e,i){const s=ki(i.padding);return"center"===e?t.x+t.width/2:"right"===e?t.x+t.width-s.right:t.x+s.left}function Ra(t){return Pa([],Da(t))}function Ia(t,e){const i=e&&e.dataset&&e.dataset.tooltip&&e.dataset.tooltip.callbacks;return i?t.override(i):t}const za={beforeTitle:e,title(t){if(t.length>0){const e=t[0],i=e.chart.data.labels,s=i?i.length:0;if(this&&this.options&&"dataset"===this.options.mode)return e.dataset.label||"";if(e.label)return e.label;if(s>0&&e.dataIndex{const e={before:[],lines:[],after:[]},n=Ia(i,t);Pa(e.before,Da(Fa(n,"beforeLabel",this,t))),Pa(e.lines,Fa(n,"label",this,t)),Pa(e.after,Da(Fa(n,"afterLabel",this,t))),s.push(e)})),s}getAfterBody(t,e){return Ra(Fa(e.callbacks,"afterBody",this,t))}getFooter(t,e){const{callbacks:i}=e,s=Fa(i,"beforeFooter",this,t),n=Fa(i,"footer",this,t),o=Fa(i,"afterFooter",this,t);let a=[];return a=Pa(a,Da(s)),a=Pa(a,Da(n)),a=Pa(a,Da(o)),a}_createItems(t){const e=this._active,i=this.chart.data,s=[],n=[],o=[];let a,r,l=[];for(a=0,r=e.length;at.filter(e,s,n,i)))),t.itemSort&&(l=l.sort(((e,s)=>t.itemSort(e,s,i)))),u(l,(e=>{const i=Ia(t.callbacks,e);s.push(Fa(i,"labelColor",this,e)),n.push(Fa(i,"labelPointStyle",this,e)),o.push(Fa(i,"labelTextColor",this,e))})),this.labelColors=s,this.labelPointStyles=n,this.labelTextColors=o,this.dataPoints=l,l}update(t,e){const i=this.options.setContext(this.getContext()),s=this._active;let n,o=[];if(s.length){const t=Sa[i.position].call(this,s,this._eventPosition);o=this._createItems(i),this.title=this.getTitle(o,i),this.beforeBody=this.getBeforeBody(o,i),this.body=this.getBody(o,i),this.afterBody=this.getAfterBody(o,i),this.footer=this.getFooter(o,i);const e=this._size=Oa(this,i),a=Object.assign({},t,e),r=Ta(this.chart,i,a),l=La(i,a,r,this.chart);this.xAlign=r.xAlign,this.yAlign=r.yAlign,n={opacity:1,x:l.x,y:l.y,width:e.width,height:e.height,caretX:t.x,caretY:t.y}}else 0!==this.opacity&&(n={opacity:0});this._tooltipItems=o,this.$context=void 0,n&&this._resolveAnimations().update(this,n),t&&i.external&&i.external.call(this,{chart:this.chart,tooltip:this,replay:e})}drawCaret(t,e,i,s){const n=this.getCaretPosition(t,i,s);e.lineTo(n.x1,n.y1),e.lineTo(n.x2,n.y2),e.lineTo(n.x3,n.y3)}getCaretPosition(t,e,i){const{xAlign:s,yAlign:n}=this,{caretSize:o,cornerRadius:a}=i,{topLeft:r,topRight:l,bottomLeft:h,bottomRight:c}=wi(a),{x:d,y:u}=t,{width:f,height:g}=e;let p,m,b,x,_,y;return"center"===n?(_=u+g/2,"left"===s?(p=d,m=p-o,x=_+o,y=_-o):(p=d+f,m=p+o,x=_-o,y=_+o),b=p):(m="left"===s?d+Math.max(r,h)+o:"right"===s?d+f-Math.max(l,c)-o:this.caretX,"top"===n?(x=u,_=x-o,p=m-o,b=m+o):(x=u+g,_=x+o,p=m+o,b=m-o),y=x),{x1:p,x2:m,x3:b,y1:x,y2:_,y3:y}}drawTitle(t,e,i){const s=this.title,n=s.length;let o,a,r;if(n){const l=Oi(i.rtl,this.x,this.width);for(t.x=Ea(this,i.titleAlign,i),e.textAlign=l.textAlign(i.titleAlign),e.textBaseline="middle",o=Si(i.titleFont),a=i.titleSpacing,e.fillStyle=i.titleColor,e.font=o.string,r=0;r0!==t))?(t.beginPath(),t.fillStyle=n.multiKeyBackground,He(t,{x:e,y:g,w:h,h:l,radius:r}),t.fill(),t.stroke(),t.fillStyle=a.backgroundColor,t.beginPath(),He(t,{x:i,y:g+1,w:h-2,h:l-2,radius:r}),t.fill()):(t.fillStyle=n.multiKeyBackground,t.fillRect(e,g,h,l),t.strokeRect(e,g,h,l),t.fillStyle=a.backgroundColor,t.fillRect(i,g+1,h-2,l-2))}t.fillStyle=this.labelTextColors[i]}drawBody(t,e,i){const{body:s}=this,{bodySpacing:n,bodyAlign:o,displayColors:a,boxHeight:r,boxWidth:l,boxPadding:h}=i,c=Si(i.bodyFont);let d=c.lineHeight,f=0;const g=Oi(i.rtl,this.x,this.width),p=function(i){e.fillText(i,g.x(t.x+f),t.y+d/2),t.y+=d+n},m=g.textAlign(o);let b,x,_,y,v,M,w;for(e.textAlign=o,e.textBaseline="middle",e.font=c.string,t.x=Ea(this,m,i),e.fillStyle=i.bodyColor,u(this.beforeBody,p),f=a&&"right"!==m?"center"===o?l/2+h:l+2+h:0,y=0,M=s.length;y0&&e.stroke()}_updateAnimationTarget(t){const e=this.chart,i=this.$animations,s=i&&i.x,n=i&&i.y;if(s||n){const i=Sa[t.position].call(this,this._active,this._eventPosition);if(!i)return;const o=this._size=Oa(this,t),a=Object.assign({},i,this._size),r=Ta(e,t,a),l=La(t,a,r,e);s._to===l.x&&n._to===l.y||(this.xAlign=r.xAlign,this.yAlign=r.yAlign,this.width=o.width,this.height=o.height,this.caretX=i.x,this.caretY=i.y,this._resolveAnimations().update(this,l))}}_willRender(){return!!this.opacity}draw(t){const e=this.options.setContext(this.getContext());let i=this.opacity;if(!i)return;this._updateAnimationTarget(e);const s={width:this.width,height:this.height},n={x:this.x,y:this.y};i=Math.abs(i)<.001?0:i;const o=ki(e.padding),a=this.title.length||this.beforeBody.length||this.body.length||this.afterBody.length||this.footer.length;e.enabled&&a&&(t.save(),t.globalAlpha=i,this.drawBackground(n,t,s,e),Ai(t,e.textDirection),n.y+=o.top,this.drawTitle(n,t,e),this.drawBody(n,t,e),this.drawFooter(n,t,e),Ti(t,e.textDirection),t.restore())}getActiveElements(){return this._active||[]}setActiveElements(t,e){const i=this._active,s=t.map((({datasetIndex:t,index:e})=>{const i=this.chart.getDatasetMeta(t);if(!i)throw new Error("Cannot find a dataset at index "+t);return{datasetIndex:t,element:i.data[e],index:e}})),n=!f(i,s),o=this._positionChanged(s,e);(n||o)&&(this._active=s,this._eventPosition=e,this._ignoreReplayEvents=!0,this.update(!0))}handleEvent(t,e,i=!0){if(e&&this._ignoreReplayEvents)return!1;this._ignoreReplayEvents=!1;const s=this.options,n=this._active||[],o=this._getActiveElements(t,n,e,i),a=this._positionChanged(o,t),r=e||!f(o,n)||a;return r&&(this._active=o,(s.enabled||s.external)&&(this._eventPosition={x:t.x,y:t.y},this.update(!0,e))),r}_getActiveElements(t,e,i,s){const n=this.options;if("mouseout"===t.type)return[];if(!s)return e.filter((t=>this.chart.data.datasets[t.datasetIndex]&&void 0!==this.chart.getDatasetMeta(t.datasetIndex).controller.getParsed(t.index)));const o=this.chart.getElementsAtEventForMode(t,n.mode,n,i);return n.reverse&&o.reverse(),o}_positionChanged(t,e){const{caretX:i,caretY:s,options:n}=this,o=Sa[n.position].call(this,t,e);return!1!==o&&(i!==o.x||s!==o.y)}}var Ba={id:"tooltip",_element:Va,positioners:Sa,afterInit(t,e,i){i&&(t.tooltip=new Va({chart:t,options:i}))},beforeUpdate(t,e,i){t.tooltip&&t.tooltip.initialize(i)},reset(t,e,i){t.tooltip&&t.tooltip.initialize(i)},afterDraw(t){const e=t.tooltip;if(e&&e._willRender()){const i={tooltip:e};if(!1===t.notifyPlugins("beforeTooltipDraw",{...i,cancelable:!0}))return;e.draw(t.ctx),t.notifyPlugins("afterTooltipDraw",i)}},afterEvent(t,e){if(t.tooltip){const i=e.replay;t.tooltip.handleEvent(e.event,i,e.inChartArea)&&(e.changed=!0)}},defaults:{enabled:!0,external:null,position:"average",backgroundColor:"rgba(0,0,0,0.8)",titleColor:"#fff",titleFont:{weight:"bold"},titleSpacing:2,titleMarginBottom:6,titleAlign:"left",bodyColor:"#fff",bodySpacing:2,bodyFont:{},bodyAlign:"left",footerColor:"#fff",footerSpacing:2,footerMarginTop:6,footerFont:{weight:"bold"},footerAlign:"left",padding:6,caretPadding:2,caretSize:5,cornerRadius:6,boxHeight:(t,e)=>e.bodyFont.size,boxWidth:(t,e)=>e.bodyFont.size,multiKeyBackground:"#fff",displayColors:!0,boxPadding:0,borderColor:"rgba(0,0,0,0)",borderWidth:0,animation:{duration:400,easing:"easeOutQuart"},animations:{numbers:{type:"number",properties:["x","y","width","height","caretX","caretY"]},opacity:{easing:"linear",duration:200}},callbacks:za},defaultRoutes:{bodyFont:"font",footerFont:"font",titleFont:"font"},descriptors:{_scriptable:t=>"filter"!==t&&"itemSort"!==t&&"external"!==t,_indexable:!1,callbacks:{_scriptable:!1,_indexable:!1},animation:{_fallback:!1},animations:{_fallback:"animation"}},additionalOptionScopes:["interaction"]};return An.register(Yn,jo,fo,t),An.helpers={...Wi},An._adapters=Rn,An.Animation=Cs,An.Animations=Os,An.animator=xt,An.controllers=en.controllers.items,An.DatasetController=Ns,An.Element=Hs,An.elements=fo,An.Interaction=Xi,An.layouts=as,An.platforms=Ss,An.Scale=Js,An.Ticks=ae,Object.assign(An,Yn,jo,fo,t,Ss),An.Chart=An,"undefined"!=typeof window&&(window.Chart=An),An})); +//# sourceMappingURL=chart.umd.js.map diff --git a/includes/admin/class-page.php b/includes/admin/class-page.php index 527b3f187..fe3913de2 100644 --- a/includes/admin/class-page.php +++ b/includes/admin/class-page.php @@ -67,10 +67,9 @@ public function enqueue_scripts( $hook ) { } // Enqueue Chart.js. - // TODO: Use a local copy of Chart.js. \wp_enqueue_script( 'chart-js', - 'https://cdn.jsdelivr.net/npm/chart.js', + PROGRESS_PLANNER_URL . 'assets/js/chart.min.js', [], '4.4.2', false From e62a79d37763822e9e6980243d2a523b87591979 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 19 Mar 2024 09:33:26 +0200 Subject: [PATCH 205/490] Combine update checks --- views/widgets/website-activity-score.php | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/views/widgets/website-activity-score.php b/views/widgets/website-activity-score.php index 7e9f39de5..173799652 100644 --- a/views/widgets/website-activity-score.php +++ b/views/widgets/website-activity-score.php @@ -71,21 +71,9 @@ }, ], [ - 'label' => esc_html__( 'Update plugins', 'progress-planner' ), + 'label' => esc_html__( 'Perform all updates', 'progress-planner' ), 'callback' => function () { - return ! wp_get_update_data()['counts']['plugins']; - }, - ], - [ - 'label' => esc_html__( 'Update themes', 'progress-planner' ), - 'callback' => function () { - return ! wp_get_update_data()['counts']['themes']; - }, - ], - [ - 'label' => esc_html__( 'Update WordPress', 'progress-planner' ), - 'callback' => function () { - return ! wp_get_update_data()['counts']['wordpress']; + return ! wp_get_update_data()['counts']['total']; }, ], ]; From 17120bf651c935977b0b148651b74f26c3c3e9d8 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 19 Mar 2024 09:37:59 +0200 Subject: [PATCH 206/490] Add link when updates are pending --- views/widgets/website-activity-score.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/views/widgets/website-activity-score.php b/views/widgets/website-activity-score.php index 173799652..8d289b22a 100644 --- a/views/widgets/website-activity-score.php +++ b/views/widgets/website-activity-score.php @@ -71,7 +71,9 @@ }, ], [ - 'label' => esc_html__( 'Perform all updates', 'progress-planner' ), + 'label' => 0 === wp_get_update_data()['counts']['total'] + ? esc_html__( 'Perform all updates', 'progress-planner' ) + : '' . esc_html__( 'Perform all updates', 'progress-planner' ) . '', 'callback' => function () { return ! wp_get_update_data()['counts']['total']; }, @@ -108,7 +110,7 @@ class="prpl-activities-gauge"
  • - +
From 1252ff4eed15f30020bc26af59c48f2b454c95fa Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 19 Mar 2024 09:41:30 +0200 Subject: [PATCH 207/490] Rename Scan classes --- includes/{scan => actions}/class-content.php | 2 +- includes/{scan => actions}/class-maintenance.php | 2 +- includes/class-base.php | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) rename includes/{scan => actions}/class-content.php (99%) rename includes/{scan => actions}/class-maintenance.php (98%) diff --git a/includes/scan/class-content.php b/includes/actions/class-content.php similarity index 99% rename from includes/scan/class-content.php rename to includes/actions/class-content.php index 5d4016200..6034a75ab 100644 --- a/includes/scan/class-content.php +++ b/includes/actions/class-content.php @@ -5,7 +5,7 @@ * @package ProgressPlanner */ -namespace ProgressPlanner\Scan; +namespace ProgressPlanner\Actions; use ProgressPlanner\Activities\Content_Helpers; use ProgressPlanner\Activities\Content as Content_Activity; diff --git a/includes/scan/class-maintenance.php b/includes/actions/class-maintenance.php similarity index 98% rename from includes/scan/class-maintenance.php rename to includes/actions/class-maintenance.php index 54e02aeb7..426a0f6f5 100644 --- a/includes/scan/class-maintenance.php +++ b/includes/actions/class-maintenance.php @@ -5,7 +5,7 @@ * @package ProgressPlanner */ -namespace ProgressPlanner\Scan; +namespace ProgressPlanner\Actions; use ProgressPlanner\Activities\Maintenance as Activity_Maintenance; diff --git a/includes/class-base.php b/includes/class-base.php index 9178aad81..c4cb1c995 100644 --- a/includes/class-base.php +++ b/includes/class-base.php @@ -10,8 +10,8 @@ use ProgressPlanner\Query; use ProgressPlanner\Admin\Page as Admin_page; use ProgressPlanner\Admin\Dashboard_Widget as Admin_Dashboard_Widget; -use ProgressPlanner\Scan\Content as Scan_Content; -use ProgressPlanner\Scan\Maintenance as Scan_Maintenance; +use ProgressPlanner\Actions\Content as Actions_Content; +use ProgressPlanner\Actions\Maintenance as Actions_Maintenance; use ProgressPlanner\Settings; /** @@ -52,8 +52,8 @@ public static function get_instance() { private function __construct() { new Admin_Page(); new Admin_Dashboard_Widget(); - new Scan_Content(); - new Scan_Maintenance(); + new Actions_Content(); + new Actions_Maintenance(); } /** From 2a4e26fcdb37cabf9f960719d1815d8dc12061fa Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 19 Mar 2024 12:12:00 +0200 Subject: [PATCH 208/490] refactor content-tracking hooks --- includes/actions/class-content.php | 193 ++++++++++++++++++----------- 1 file changed, 119 insertions(+), 74 deletions(-) diff --git a/includes/actions/class-content.php b/includes/actions/class-content.php index 6034a75ab..eeeb16b59 100644 --- a/includes/actions/class-content.php +++ b/includes/actions/class-content.php @@ -42,28 +42,56 @@ public function __construct() { * Register hooks. */ public function register_hooks() { - \add_action( 'save_post', [ $this, 'save_post' ], 10, 2 ); + // Add activity when a post is updated. + \add_action( 'post_updated', [ $this, 'post_updated' ], 10, 2 ); + + // Add activity when a post is added. \add_action( 'wp_insert_post', [ $this, 'insert_post' ], 10, 2 ); \add_action( 'transition_post_status', [ $this, 'transition_post_status' ], 10, 3 ); + + // Add activity when a post is trashed or deleted. \add_action( 'wp_trash_post', [ $this, 'trash_post' ] ); \add_action( 'delete_post', [ $this, 'delete_post' ] ); - \add_action( 'pre_post_update', [ $this, 'pre_post_update' ], 10, 2 ); + // Add hooks to handle scanning existing posts. \add_action( 'wp_ajax_progress_planner_scan_posts', [ $this, 'ajax_scan' ] ); \add_action( 'wp_ajax_progress_planner_reset_stats', [ $this, 'ajax_reset_stats' ] ); } - /** - * Save post stats. + * Post updated. * - * Runs on save_post hook. + * Runs on post_updated hook. * * @param int $post_id The post ID. * @param WP_Post $post The post object. + * + * @return void */ - public function save_post( $post_id, $post ) { - $this->insert_post( $post_id, $post ); + public function post_updated( $post_id, $post ) { + // Bail if we should skip saving. + if ( $this->should_skip_saving( $post ) ) { + return; + } + + // Check if there is an update activity for this post, on this date. + $existing = \progress_planner()->get_query()->query_activities( + [ + 'category' => 'content', + 'type' => 'update', + 'data_id' => $post_id, + 'start_date' => Date::get_datetime_from_mysql_date( $post->post_modified )->modify( '-12 hours' ), + 'end_date' => Date::get_datetime_from_mysql_date( $post->post_modified )->modify( '+12 hours' ), + ], + 'RAW' + ); + + // If there is an update activity for this post, on this date, bail. + if ( ! empty( $existing ) ) { + return; + } + + $this->add_post_activity( $post, 'update' ); } /** @@ -81,9 +109,23 @@ public function insert_post( $post_id, $post ) { return; } + // Check if there is an publish activity for this post. + $existing = \progress_planner()->get_query()->query_activities( + [ + 'category' => 'content', + 'type' => 'publish', + 'data_id' => $post_id, + ], + 'RAW' + ); + + // If there is a publish activity for this post, bail. + if ( ! empty( $existing ) ) { + return; + } + // Add a publish activity. - $activity = Content_Helpers::get_activity_from_post( $post ); - $activity->save(); + $this->add_post_activity( $post, 'publish' ); } /** @@ -95,56 +137,15 @@ public function insert_post( $post_id, $post ) { */ public function transition_post_status( $new_status, $old_status, $post ) { // Bail if we should skip saving. - if ( $this->should_skip_saving( $post ) ) { + if ( $this->should_skip_saving( $post ) || + $new_status === $old_status || + ( 'publish' !== $new_status && 'publish' !== $old_status ) + ) { return; } - // If the post is published, check if it was previously published, - // and if so, delete the old activity before creating the new one. - if ( 'publish' !== $old_status && 'publish' === $new_status ) { - $old_publish_activities = \progress_planner()->get_query()->query_activities( - [ - 'category' => 'content', - 'type' => 'publish', - 'data_id' => $post->ID, - ] - ); - if ( ! empty( $old_publish_activities ) ) { - foreach ( $old_publish_activities as $activity ) { - $activity->delete(); - } - } - } - // Add activity. - $activity = Content_Helpers::get_activity_from_post( $post ); - return $activity->save(); - } - - /** - * Update a post. - * - * Runs on pre_post_update hook. - * - * @param int $post_id The post ID. - * @param WP_Post $post The post object. - * - * @return bool - */ - public function pre_post_update( $post_id, $post ) { - // Bail if we should skip saving. - if ( get_post( $post_id ) && $this->should_skip_saving( get_post( $post_id ) ) ) { - return; - } - - $post_array = (array) $post; - // Add an update activity. - $activity = new Content_Activity(); - $activity->set_type( 'update' ); - $activity->set_date( Date::get_datetime_from_mysql_date( $post_array['post_modified'] ) ); - $activity->set_data_id( $post_id ); - $activity->set_user_id( (int) $post_array['post_author'] ); - return $activity->save(); + $this->add_post_activity( $post, $new_status === 'publish' ? 'publish' : 'update' ); } /** @@ -163,11 +164,7 @@ public function trash_post( $post_id ) { return; } - // Add an update activity. - $activity = Content_Helpers::get_activity_from_post( $post ); - $activity->set_type( 'update' ); - $activity->set_date( Date::get_datetime_from_mysql_date( $post->post_modified ) ); - return $activity->save(); + $this->add_post_activity( $post, 'trash' ); } /** @@ -186,18 +183,13 @@ public function delete_post( $post_id ) { return; } - // Update existing activities. - $activities = \progress_planner()->get_query()->query_activities( - [ - 'category' => 'content', - 'data_id' => $post->ID, - ] - ); - if ( ! empty( $activities ) ) { - \progress_planner()->get_query()->delete_activities( $activities ); - } - - $activity = Content_Helpers::get_activity_from_post( $post ); + // Add activity. + $activity = new Content_Activity(); + $activity->set_category( 'content' ); + $activity->set_type( 'delete' ); + $activity->set_data_id( $post_id ); + $activity->set_date( new \DateTime() ); + $activity->set_user_id( get_current_user_id() ); $activity->save(); } @@ -210,8 +202,11 @@ public function delete_post( $post_id ) { */ private function should_skip_saving( $post ) { // Bail if the post is not included in the post-types we're tracking. - $post_types = Content_Helpers::get_post_types_names(); - if ( ! \in_array( $post->post_type, $post_types, true ) ) { + if ( ! \in_array( + $post->post_type, + Content_Helpers::get_post_types_names(), + true + ) ) { return true; } @@ -228,6 +223,56 @@ private function should_skip_saving( $post ) { return false; } + /** + * Add an update activity. + * + * @param \WP_Post $post The post object. + * @param string $type The type of activity. + * + * @return void + */ + private function add_post_activity( $post, $type ) { + if ( 'update' === $type ) { + if ( 'publish' === $post->post_status ) { + // Check if there is a publish activity for this post. + $existing = \progress_planner()->get_query()->query_activities( + [ + 'category' => 'content', + 'type' => 'publish', + 'data_id' => $post_id, + ], + 'RAW' + ); + + // If there is no publish activity for this post, add it. + if ( empty( $existing ) ) { + $this->add_post_activity( $post, 'publish' ); + return; + } + } + + // Check if there are any activities for this post, on this date. + $existing = \progress_planner()->get_query()->query_activities( + [ + 'category' => 'content', + 'data_id' => $post->ID, + 'start_date' => Date::get_datetime_from_mysql_date( $post->post_modified )->modify( '-12 hours' ), + 'end_date' => Date::get_datetime_from_mysql_date( $post->post_modified )->modify( '+12 hours' ), + ], + 'RAW' + ); + + // If there are activities for this post, on this date, bail. + if ( ! empty( $existing ) ) { + return; + } + } + + $activity = Content_Helpers::get_activity_from_post( $post ); + $activity->set_type( $type ); + $activity->save(); + } + /** * Update stats for posts. * - Gets the next page to scan. From eab8de23fb8d6e3c4057c5f0adbb918da50d8788 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 20 Mar 2024 10:11:11 +0200 Subject: [PATCH 209/490] Temporary fix for duplicate entries --- includes/class-query.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/includes/class-query.php b/includes/class-query.php index 93fc1a3dc..00089efab 100644 --- a/includes/class-query.php +++ b/includes/class-query.php @@ -178,6 +178,15 @@ public function query_activities( $args, $return_type = 'ACTIVITIES' ) { return []; } + // Remove duplicates. + // TODO: This is a temporary fix. We should not have duplicates in the first place. + // This has already been fixed, but for test-sites there are some duplicates remaining. + $results_unique = []; + foreach ( $results as $key => $result ) { + $results_unique[ $result->category . $result->type . $result->data_id . $result->date ] = $result; + } + $results = array_values( $results_unique ); + return 'RAW' === $return_type ? $results : $this->get_activities_from_results( $results ); From 7393f76bf7df3be941ffdc959742dadf287eaff1 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 20 Mar 2024 10:11:27 +0200 Subject: [PATCH 210/490] tweak graph --- views/widgets/published-content.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/widgets/published-content.php b/views/widgets/published-content.php index 5a08aa0ff..506a67009 100644 --- a/views/widgets/published-content.php +++ b/views/widgets/published-content.php @@ -80,7 +80,7 @@ 'chart_params' => [ 'type' => 'line', ], - 'additive' => true, + 'additive' => false, ], ); ?> From 91a0392df52069a87be1348f28e5bf48b22a1c45 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 20 Mar 2024 10:30:59 +0200 Subject: [PATCH 211/490] latest-badge widget --- assets/css/admin.css | 14 ++++++++++++++ views/widgets/latest-badge.php | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/assets/css/admin.css b/assets/css/admin.css index aa0131dfd..de8bb4132 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -374,3 +374,17 @@ .prpl-widget-wrapper.prpl-whats-new li > a > h3 { text-decoration: underline; } + +/*------------------------------------*\ + Latest badge widget. +\*------------------------------------*/ +.prpl-badge-wrapper.prpl-badge-latest { + background: var(--prpl-background-blue); + padding: var(--prpl-padding); + border-radius: var(--prpl-border-radius); + border: 1px solid var(--prpl-color-accent-green); +} + +.prpl-badge-wrapper.prpl-badge-latest .badge-svg { + align-self: start; +} diff --git a/views/widgets/latest-badge.php b/views/widgets/latest-badge.php index 8eba06276..915885e52 100644 --- a/views/widgets/latest-badge.php +++ b/views/widgets/latest-badge.php @@ -51,4 +51,18 @@ ); ?>

+
+
+ +
+
+ ' . esc_html( $prpl_latest_badge['name'] ) . '' + ); + ?> +
+
From cf8dccca87a1bab2d1d22c2564770418736fba09 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 20 Mar 2024 11:03:43 +0200 Subject: [PATCH 212/490] Remove trailing slash from PROGRESS_PLANNER_URL --- includes/admin/class-page.php | 6 +++--- progress-planner.php | 2 +- views/admin-page-header.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/includes/admin/class-page.php b/includes/admin/class-page.php index fe3913de2..cc68ed2ab 100644 --- a/includes/admin/class-page.php +++ b/includes/admin/class-page.php @@ -69,7 +69,7 @@ public function enqueue_scripts( $hook ) { // Enqueue Chart.js. \wp_enqueue_script( 'chart-js', - PROGRESS_PLANNER_URL . 'assets/js/chart.min.js', + PROGRESS_PLANNER_URL . '/assets/js/chart.min.js', [], '4.4.2', false @@ -77,7 +77,7 @@ public function enqueue_scripts( $hook ) { \wp_enqueue_script( 'progress-planner-admin', - PROGRESS_PLANNER_URL . 'assets/js/admin.js', + PROGRESS_PLANNER_URL . '/assets/js/admin.js', [], filemtime( PROGRESS_PLANNER_DIR . '/assets/js/admin.js' ), true @@ -98,7 +98,7 @@ public function enqueue_scripts( $hook ) { \wp_enqueue_style( 'progress-planner-admin', - PROGRESS_PLANNER_URL . 'assets/css/admin.css', + PROGRESS_PLANNER_URL . '/assets/css/admin.css', [], filemtime( PROGRESS_PLANNER_DIR . '/assets/css/admin.css' ) ); diff --git a/progress-planner.php b/progress-planner.php index 2ad632391..be9eba78b 100644 --- a/progress-planner.php +++ b/progress-planner.php @@ -6,7 +6,7 @@ */ define( 'PROGRESS_PLANNER_DIR', __DIR__ ); -define( 'PROGRESS_PLANNER_URL', plugin_dir_url( __FILE__ ) ); +define( 'PROGRESS_PLANNER_URL', untrailingslashit( plugin_dir_url( __FILE__ ) ) ); require_once PROGRESS_PLANNER_DIR . '/includes/autoload.php'; diff --git a/views/admin-page-header.php b/views/admin-page-header.php index 2e4cd0232..ab89ca01d 100644 --- a/views/admin-page-header.php +++ b/views/admin-page-header.php @@ -14,7 +14,7 @@ diff --git a/views/widgets/badges-progress.php b/views/widgets/badges-progress.php index 25c640994..04cc8d145 100644 --- a/views/widgets/badges-progress.php +++ b/views/widgets/badges-progress.php @@ -7,8 +7,12 @@ namespace ProgressPlanner; -// Get an array of badges. -$prpl_badges = \progress_planner()->get_badges()->get_badges(); +use ProgressPlanner\Badges; + +$prpl_badges = [ + 'content' => [ 'wonderful-writer', 'awesome-author', 'notorious-novelist' ], + 'maintenance' => [ 'progress-professional', 'maintenance-maniac', 'super-site-specialist' ], +]; /** * Callback to get the progress color. @@ -33,26 +37,24 @@ - - + $prpl_category_badges ) : ?>
- get_badges()->get_badge_progress( $prpl_badge['id'] ); ?> - $prpl_badge_step_progress ) : ?> - + + -

+

diff --git a/views/widgets/latest-badge.php b/views/widgets/latest-badge.php index 915885e52..1a47504d0 100644 --- a/views/widgets/latest-badge.php +++ b/views/widgets/latest-badge.php @@ -8,32 +8,26 @@ namespace ProgressPlanner; use ProgressPlanner\Settings; +use ProgressPlanner\Badges; // Get the settings for badges. -$prpl_badges_settings = Settings::get( 'badges' ); -$prpl_latest_badge_date = null; -$prpl_latest_badge_details = null; +$prpl_badges_settings = Settings::get( 'badges' ); +$prpl_latest_badge_date = null; +$prpl_latest_badge = null; +$prpl_latest_badge_id = null; foreach ( $prpl_badges_settings as $prpl_badge_id => $prpl_badge_settings ) { - foreach ( $prpl_badge_settings as $prpl_badge_target => $prpl_badge_progress ) { - if ( isset( $prpl_badge_progress['progress'] ) && 100 === $prpl_badge_progress['progress'] ) { - if ( null === $prpl_latest_badge_date || - \DateTime::createFromFormat( 'Y-m-d H:i:s', $prpl_badge_progress['date'] )->format( 'U' ) > \DateTime::createFromFormat( 'Y-m-d H:i:s', $prpl_latest_badge_date )->format( 'U' ) - ) { - $prpl_latest_badge_date = $prpl_badge_progress['date']; - $prpl_latest_badge_details = [ $prpl_badge_id, $prpl_badge_target ]; - } + if ( isset( $prpl_badge_settings['progress'] ) && 100 === $prpl_badge_settings['progress'] ) { + if ( null === $prpl_latest_badge_date || + \DateTime::createFromFormat( 'Y-m-d H:i:s', $prpl_badge_settings['date'] )->format( 'U' ) > \DateTime::createFromFormat( 'Y-m-d H:i:s', $prpl_latest_badge_date )->format( 'U' ) + ) { + $prpl_latest_badge_date = $prpl_badge_settings['date']; + $prpl_latest_badge_id = $prpl_badge_id; } } } -if ( $prpl_latest_badge_details ) { - $prpl_latest_badge = \progress_planner()->get_badges()->get_badge( $prpl_latest_badge_details[0] ); - foreach ( $prpl_latest_badge['steps'] as $prpl_badge_step ) { - if ( $prpl_badge_step['target'] === $prpl_latest_badge_details[1] ) { - $prpl_latest_badge = $prpl_badge_step; - break; - } - } +if ( $prpl_latest_badge_id ) { + $prpl_latest_badge = Badges::get_badge( $prpl_latest_badge_id ); } ?>

diff --git a/views/widgets/personal-record-content.php b/views/widgets/personal-record-content.php index eefcbacdc..0a7d2a193 100644 --- a/views/widgets/personal-record-content.php +++ b/views/widgets/personal-record-content.php @@ -7,7 +7,9 @@ namespace ProgressPlanner; -$prpl_personal_record_content = \progress_planner()->get_badges()->get_badge_progress( 'personal_record_content' ); +use ProgressPlanner\Badges; + +$prpl_personal_record_content = Badges::get_badge_progress( 'personal_record_content' ); ?>
From a641d60cd3d362c1d658769d55cc517147006217 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 21 Mar 2024 11:01:33 +0200 Subject: [PATCH 215/490] fix latest-badge widget --- views/widgets/latest-badge.php | 37 ++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/views/widgets/latest-badge.php b/views/widgets/latest-badge.php index 1a47504d0..883caa4bd 100644 --- a/views/widgets/latest-badge.php +++ b/views/widgets/latest-badge.php @@ -10,19 +10,40 @@ use ProgressPlanner\Settings; use ProgressPlanner\Badges; +$prpl_badges = [ + 'wonderful-writer', + 'awesome-author', + 'notorious-novelist', + 'progress-professional', + 'maintenance-maniac', + 'super-site-specialist', +]; // Get the settings for badges. -$prpl_badges_settings = Settings::get( 'badges' ); +$prpl_badges_settings = Settings::get( 'badges', [] ); $prpl_latest_badge_date = null; $prpl_latest_badge = null; $prpl_latest_badge_id = null; -foreach ( $prpl_badges_settings as $prpl_badge_id => $prpl_badge_settings ) { - if ( isset( $prpl_badge_settings['progress'] ) && 100 === $prpl_badge_settings['progress'] ) { - if ( null === $prpl_latest_badge_date || - \DateTime::createFromFormat( 'Y-m-d H:i:s', $prpl_badge_settings['date'] )->format( 'U' ) > \DateTime::createFromFormat( 'Y-m-d H:i:s', $prpl_latest_badge_date )->format( 'U' ) - ) { - $prpl_latest_badge_date = $prpl_badge_settings['date']; - $prpl_latest_badge_id = $prpl_badge_id; +foreach ( $prpl_badges as $prpl_badge_id ) { + $prpl_badge_progress = Badges::get_badge_progress( $prpl_badge_id ); + if ( 100 !== $prpl_badge_progress['percent'] ) { + continue; + } + if ( null === $prpl_latest_badge_date ) { + $prpl_latest_badge_id = $prpl_badge_id; + if ( isset( $prpl_badges_settings[ $prpl_badge_id ]['date'] ) ) { + $prpl_latest_badge_date = $prpl_badges_settings[ $prpl_badge_id ]['date']; } + continue; + } + $prpl_badge_settings = $prpl_badges_settings[ $prpl_badge_id ]; + if ( ! isset( $prpl_badge_settings['date'] ) ) { + continue; + } + if ( null === $prpl_latest_badge_date || + \DateTime::createFromFormat( 'Y-m-d H:i:s', $prpl_badge_settings['date'] )->format( 'U' ) > \DateTime::createFromFormat( 'Y-m-d H:i:s', $prpl_latest_badge_date )->format( 'U' ) + ) { + $prpl_latest_badge_date = $prpl_badge_settings['date']; + $prpl_latest_badge_id = $prpl_badge_id; } } From f7710969d9de5985efcf7175af3e793fbe782b59 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 21 Mar 2024 11:47:00 +0200 Subject: [PATCH 216/490] cleanup --- includes/admin/class-dashboard-widget.php | 8 +- includes/class-base.php | 10 +-- includes/class-chart.php | 6 +- includes/class-date.php | 2 +- includes/class-query.php | 6 +- views/admin-page-debug.php | 22 ----- views/admin-page-form-scan.php | 8 +- views/admin-page-header.php | 38 ++++----- views/admin-page.php | 11 +-- views/widgets/activity-scores.php | 6 +- views/widgets/badge-content.php | 14 ++-- views/widgets/badge-streak.php | 14 ++-- views/widgets/badges-progress.php | 4 +- views/widgets/latest-badge.php | 12 +-- views/widgets/personal-record-content.php | 20 ++--- views/widgets/plugins.php | 14 ++-- views/widgets/published-content-density.php | 14 ++-- views/widgets/published-content.php | 32 ++++---- views/widgets/published-pages.php | 90 --------------------- views/widgets/published-posts.php | 90 --------------------- views/widgets/published-words.php | 14 ++-- views/widgets/website-activity-score.php | 24 +++--- views/widgets/whats-new.php | 8 +- 23 files changed, 130 insertions(+), 337 deletions(-) delete mode 100644 views/admin-page-debug.php delete mode 100644 views/widgets/published-pages.php delete mode 100644 views/widgets/published-posts.php diff --git a/includes/admin/class-dashboard-widget.php b/includes/admin/class-dashboard-widget.php index 8db9f854a..bd1fb86c9 100644 --- a/includes/admin/class-dashboard-widget.php +++ b/includes/admin/class-dashboard-widget.php @@ -23,9 +23,9 @@ public function __construct() { * Add the dashboard widget. */ public function add_dashboard_widget() { - wp_add_dashboard_widget( + \wp_add_dashboard_widget( 'prpl_dashboard_widget', - esc_html__( 'Progress Planner', 'progress-planner' ), + \esc_html__( 'Progress Planner', 'progress-planner' ), [ $this, 'render_dashboard_widget' ] ); } @@ -40,8 +40,8 @@ public function render_dashboard_widget() { ?> [], @@ -62,7 +62,7 @@ public function the_chart( $args = [] ) { 'max' => null, ] ); - $args['chart_params'] = wp_parse_args( + $args['chart_params'] = \wp_parse_args( $args['chart_params'], [ 'type' => 'line', @@ -213,7 +213,7 @@ public function the_chart( $args = [] ) { // Render the chart. $this->render_chart_js( - md5( wp_json_encode( $args ) ) . wp_rand( 0, 1000 ), + md5( \wp_json_encode( $args ) ) . \wp_rand( 0, 1000 ), $args['chart_params']['type'], $data, $args['chart_params']['options'] diff --git a/includes/class-date.php b/includes/class-date.php index a4ecae9b3..cf7f3551f 100644 --- a/includes/class-date.php +++ b/includes/class-date.php @@ -87,7 +87,7 @@ public static function get_periods( $start, $end, $frequency ) { * @return \DateTime */ public static function get_datetime_from_mysql_date( $date ) { - return \DateTime::createFromFormat( 'U', (int) mysql2date( 'U', $date ) ); + return \DateTime::createFromFormat( 'U', (int) \mysql2date( 'U', $date ) ); } /** diff --git a/includes/class-query.php b/includes/class-query.php index 00089efab..a57a00c30 100644 --- a/includes/class-query.php +++ b/includes/class-query.php @@ -115,8 +115,8 @@ public function query_activities( $args, $return_type = 'ACTIVITIES' ) { $args = \wp_parse_args( $args, $defaults ); - $cache_key = 'progress-planner-activities-' . md5( wp_json_encode( $args ) ); - $results = wp_cache_get( $cache_key ); + $cache_key = 'progress-planner-activities-' . md5( \wp_json_encode( $args ) ); + $results = \wp_cache_get( $cache_key ); if ( false === $results ) { $where_args = []; @@ -171,7 +171,7 @@ public function query_activities( $args, $return_type = 'ACTIVITIES' ) { ) ); - wp_cache_set( $cache_key, $results ); + \wp_cache_set( $cache_key, $results ); } if ( ! $results ) { diff --git a/views/admin-page-debug.php b/views/admin-page-debug.php deleted file mode 100644 index b01d8350c..000000000 --- a/views/admin-page-debug.php +++ /dev/null @@ -1,22 +0,0 @@ - -
-
- -
-
-
- -
-		get_query()->query_activities( [] ) );
-		?>
-	
-
diff --git a/views/admin-page-form-scan.php b/views/admin-page-form-scan.php index f3c2c3434..f10029673 100644 --- a/views/admin-page-form-scan.php +++ b/views/admin-page-form-scan.php @@ -6,12 +6,12 @@ */ ?> -

-

+

+

- +
diff --git a/views/admin-page-header.php b/views/admin-page-header.php index ab89ca01d..7b11d6f84 100644 --- a/views/admin-page-header.php +++ b/views/admin-page-header.php @@ -6,56 +6,56 @@ */ // phpcs:ignore WordPress.Security.NonceVerification.Recommended -$prpl_active_range = isset( $_GET['range'] ) ? sanitize_text_field( wp_unslash( $_GET['range'] ) ) : '-6 months'; +$prpl_active_range = isset( $_GET['range'] ) ? \sanitize_text_field( \wp_unslash( $_GET['range'] ) ) : '-6 months'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -$prpl_active_frequency = isset( $_GET['frequency'] ) ? sanitize_text_field( wp_unslash( $_GET['frequency'] ) ) : 'monthly'; +$prpl_active_frequency = isset( $_GET['frequency'] ) ? \sanitize_text_field( \wp_unslash( $_GET['frequency'] ) ) : 'monthly'; ?>
From ee422d4713c398d717cf4610dcff658c30352b4f Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 27 Mar 2024 15:05:03 +0200 Subject: [PATCH 258/490] Change the dashboard widget to show just the gauge --- assets/css/admin.css | 22 +++-- includes/admin/class-dashboard-widget.php | 8 +- .../widgets/class-website-activity-score.php | 80 ++++++++++++------- 3 files changed, 64 insertions(+), 46 deletions(-) diff --git a/assets/css/admin.css b/assets/css/admin.css index 42b97af41..974d640b3 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -1,7 +1,7 @@ /*------------------------------------*\ Set variables. \*------------------------------------*/ -.prpl-wrap { +:root { --prpl-gap: 32px; --prpl-padding: 20px; --prpl-column-min-width: 16rem; @@ -216,10 +216,16 @@ grid-template-columns: 6fr 4fr; } -.prpl-widget-wrapper.prpl-website-activity-score .prpl-gauge-number { +.prpl-gauge-number { font-size: var(--prpl-font-size-4xl); - line-height: 1; margin-top: -1em; + display: block; + padding-top: 50%; + font-weight: 700; + text-align: center; + position: absolute; + width: 100%; + line-height: 2; } .prpl-activities-gauge-container { @@ -231,16 +237,6 @@ top: 50%; } -.prpl-activities-gauge-container .prpl-gauge-number { - display: block; - padding-top: 50%; - font-weight: 700; - text-align: center; - position: absolute; - width: 100%; - line-height: 2; -} - /*------------------------------------*\ Activity scores \*------------------------------------*/ diff --git a/includes/admin/class-dashboard-widget.php b/includes/admin/class-dashboard-widget.php index 2fe759f82..ef3c1b382 100644 --- a/includes/admin/class-dashboard-widget.php +++ b/includes/admin/class-dashboard-widget.php @@ -7,6 +7,8 @@ namespace ProgressPlanner\Admin; +use ProgressPlanner\Admin\Page; + /** * Class Dashboard_Widget */ @@ -34,11 +36,9 @@ public function add_dashboard_widget() { * Render the dashboard widget. */ public function render_dashboard_widget() { - // Enqueue Chart.js. - // TODO: Use a local copy of Chart.js and properly enqueue it. - echo ''; + Page::enqueue_styles(); echo '
'; - new \ProgressPlanner\Widgets\Activity_Scores(); + \ProgressPlanner\Widgets\Website_Activity_Score::print_score_gauge(); echo ''; \esc_html_e( 'See more details', 'progress-planner' ); diff --git a/includes/widgets/class-website-activity-score.php b/includes/widgets/class-website-activity-score.php index eedf92e2b..e03d6ca2d 100644 --- a/includes/widgets/class-website-activity-score.php +++ b/includes/widgets/class-website-activity-score.php @@ -25,52 +25,74 @@ class Website_Activity_Score extends Widget { * Render the widget content. */ public function the_content() { - $score = $this->get_score(); ?>

-
-
-
- - - -
-
- -
+
-
    - get_checklist() as $checklist_item ) : ?> -
  • - - -
  • - -
+ print_weekly_activities_checklist(); ?> +
+
+ +
+
+
+ + + +
+
+
    + get_checklist() as $checklist_item ) : ?> +
  • + + +
  • + +
+ get_query()->query_activities( [ // Use 31 days to take into account @@ -145,7 +167,7 @@ public function get_checklist() { * * @return string The color. */ - public function get_gauge_color( $score ) { + protected static function get_gauge_color( $score ) { if ( $score >= 75 ) { return 'var(--prpl-color-accent-green)'; } From 221d52ce006b9a46246d55b3c6d87755a3a7463d Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 27 Mar 2024 15:10:48 +0200 Subject: [PATCH 259/490] bugfix for widget :poop: --- includes/widgets/class-website-activity-score.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/widgets/class-website-activity-score.php b/includes/widgets/class-website-activity-score.php index e03d6ca2d..bac5cc83e 100644 --- a/includes/widgets/class-website-activity-score.php +++ b/includes/widgets/class-website-activity-score.php @@ -31,7 +31,7 @@ public function the_content() {

- +
print_weekly_activities_checklist(); ?> @@ -77,7 +77,7 @@ class="prpl-activities-gauge" public static function print_weekly_activities_checklist() { ?>
From d0ed207a8b3b303d1209f70a29fce815273ddf23 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 28 Mar 2024 12:45:17 +0200 Subject: [PATCH 268/490] Add the site-URL as a parameter to generate the nonce --- includes/class-onboard.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-onboard.php b/includes/class-onboard.php index d796418e6..199672369 100644 --- a/includes/class-onboard.php +++ b/includes/class-onboard.php @@ -89,7 +89,7 @@ public static function get_remote_nonce() { if ( $stored_nonce ) { return $stored_nonce; } - $response = wp_remote_get( self::REMOTE_URL . '/wp-json/progress-planner-saas/v1/get-nonce' ); + $response = wp_remote_get( self::REMOTE_URL . '/wp-json/progress-planner-saas/v1/get-nonce/site/' . md5( \site_url() ) ); if ( is_wp_error( $response ) ) { return ''; } From 465f60c2c06f68c4f54ee6eb8e2380632f3c2dd4 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 28 Mar 2024 12:49:03 +0200 Subject: [PATCH 269/490] use the correct remote URL --- includes/class-onboard.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-onboard.php b/includes/class-onboard.php index 199672369..83fdaa521 100644 --- a/includes/class-onboard.php +++ b/includes/class-onboard.php @@ -19,7 +19,7 @@ class Onboard { * * @var string */ - const REMOTE_URL = 'http://ubuntu.orb.local'; + const REMOTE_URL = 'http://progressplanner.com'; /** * The onboarding form. From 58069056b4c5a07b762d7746b06dc00cc1bd14e4 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 28 Mar 2024 13:02:26 +0200 Subject: [PATCH 270/490] URL fix --- includes/class-onboard.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-onboard.php b/includes/class-onboard.php index 83fdaa521..c17e36eca 100644 --- a/includes/class-onboard.php +++ b/includes/class-onboard.php @@ -19,7 +19,7 @@ class Onboard { * * @var string */ - const REMOTE_URL = 'http://progressplanner.com'; + const REMOTE_URL = 'https://progressplanner.com'; /** * The onboarding form. From 66f0aa312d89a92ee6be81fadb5df8631150bead Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 29 Mar 2024 11:33:24 +0200 Subject: [PATCH 271/490] WIP - add scan form in welcome box --- views/welcome.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/views/welcome.php b/views/welcome.php index c3fce58b8..1f36067ba 100644 --- a/views/welcome.php +++ b/views/welcome.php @@ -32,4 +32,6 @@ + +
From 86606fb4021d9629100f5fa462602d5c3e31c458 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 29 Mar 2024 11:34:10 +0200 Subject: [PATCH 272/490] WIP --- assets/js/admin.js | 24 ++++++++++++++++++++++++ includes/admin/class-page.php | 9 ++++++--- includes/class-onboard.php | 21 +++++++++++++++++---- 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/assets/js/admin.js b/assets/js/admin.js index 5c3af3b35..368dbfc2c 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -163,3 +163,27 @@ if ( document.getElementById( 'prpl-dev-stats-numbers' ) ) { window.location.href = url.href; } ); } + +if ( document.getElementById( 'prpl-onboarding-form' ) ) { + document.getElementById( 'prpl-onboarding-form' ).addEventListener( 'submit', function( event ) { + event.preventDefault(); + const inputs = this.querySelectorAll( 'input' ); + const data = {}; + inputs.forEach( input => { + if ( input.name ) { + data[ input.name ] = input.value; + } + } ); + console.log( data ); + progressPlannerAjaxRequest( { + url: progressPlanner.onboardAPIUrl, + data: data, + successAction: ( response ) => { + console.log( response ); + if ( response.success ) { + // location.reload(); + } + }, + } ); + } ); +} diff --git a/includes/admin/class-page.php b/includes/admin/class-page.php index 2238f61aa..567be0d28 100644 --- a/includes/admin/class-page.php +++ b/includes/admin/class-page.php @@ -7,6 +7,8 @@ namespace ProgressPlanner\Admin; +use ProgressPlanner\Onboard; + /** * Admin page class. */ @@ -98,9 +100,10 @@ public static function enqueue_scripts() { 'progress-planner-admin', 'progressPlanner', [ - 'ajaxUrl' => \admin_url( 'admin-ajax.php' ), - 'nonce' => \wp_create_nonce( 'progress_planner_scan' ), - 'l10n' => [ + 'onboardAPIUrl' => Onboard::get_remote_url(), + 'ajaxUrl' => \admin_url( 'admin-ajax.php' ), + 'nonce' => \wp_create_nonce( 'progress_planner_scan' ), + 'l10n' => [ 'resettingStats' => \esc_html__( 'Resetting stats...', 'progress-planner' ), ], ] diff --git a/includes/class-onboard.php b/includes/class-onboard.php index c17e36eca..249713291 100644 --- a/includes/class-onboard.php +++ b/includes/class-onboard.php @@ -57,17 +57,17 @@ public static function the_form() { Date: Fri, 29 Mar 2024 13:48:30 +0200 Subject: [PATCH 273/490] minor tweak --- includes/class-onboard.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-onboard.php b/includes/class-onboard.php index 249713291..ce496ef6d 100644 --- a/includes/class-onboard.php +++ b/includes/class-onboard.php @@ -99,7 +99,7 @@ public static function get_remote_nonce() { return ''; } - if ( $data['token'] !== API::get_api_token() ) { + if ( ! isset( $data['token'] ) || $data['token'] !== API::get_api_token() ) { return ''; } From 62c3c506844ba3361f24501be90f22e97053c162 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 1 Apr 2024 11:19:04 +0300 Subject: [PATCH 274/490] WIP --- assets/js/ajax-request.js | 39 ++++++++++++++++ assets/js/onboard.js | 47 +++++++++++++++++++ assets/js/{admin.js => scan-posts.js} | 67 +-------------------------- includes/admin/class-page.php | 34 +++++++++++--- includes/class-api.php | 28 +---------- includes/class-onboard.php | 37 ++------------- views/welcome.php | 4 -- 7 files changed, 119 insertions(+), 137 deletions(-) create mode 100644 assets/js/ajax-request.js create mode 100644 assets/js/onboard.js rename assets/js/{admin.js => scan-posts.js} (64%) diff --git a/assets/js/ajax-request.js b/assets/js/ajax-request.js new file mode 100644 index 000000000..344beec36 --- /dev/null +++ b/assets/js/ajax-request.js @@ -0,0 +1,39 @@ + +/** + * A helper to make AJAX requests. + * + * @param {Object} params The callback parameters. + * @param {string} params.url The URL to send the request to. + * @param {Object} params.data The data to send with the request. + * @param {Function} params.successAction The callback to run on success. + * @param {Function} params.failAction The callback to run on failure. + */ +const progressPlannerAjaxRequest = ( { method, url, data, successAction, failAction } ) => { + const http = new XMLHttpRequest(); + http.open( method, url, true ); + http.onreadystatechange = () => { + let response; + try { + response = JSON.parse( http.response ); + } catch ( e ) { + if ( http.readyState === 4 && http.status !== 200 ) { + // eslint-disable-next-line no-console + console.warn( http, e ); + return http.response; + } + } + if ( http.readyState === 4 && http.status === 200 ) { + return successAction ? successAction( response ) : response; + } + return failAction ? failAction( response ) : response; + }; + + const dataForm = new FormData(); + + // eslint-disable-next-line prefer-const + for ( let [ key, value ] of Object.entries( data ) ) { + dataForm.append( key, value ); + } + + http.send( dataForm ); +}; diff --git a/assets/js/onboard.js b/assets/js/onboard.js new file mode 100644 index 000000000..e022906fa --- /dev/null +++ b/assets/js/onboard.js @@ -0,0 +1,47 @@ +/* global progressPlanner */ + +if ( document.getElementById( 'prpl-onboarding-form' ) ) { + document.getElementById( 'prpl-onboarding-form' ).addEventListener( 'submit', function( event ) { + event.preventDefault(); + const inputs = this.querySelectorAll( 'input' ); + + // Build the data object. + const data = {}; + inputs.forEach( input => { + if ( input.name ) { + data[ input.name ] = input.value; + } + } ); + + // Make a request to get the nonce. + // Once the nonce is received, make a request to the API. + progressPlannerAjaxRequest( { + method: 'POST', + url: progressPlanner.onboardGetNonceURL, + data: data, + successAction: ( response ) => { + if ( 'ok' === response.status ) { + + // Add the nonce to our data object. + data.nonce = response.nonce; +console.log(data); + // Make the request to the API. + progressPlannerAjaxRequest( { + method: 'POST', + url: progressPlanner.onboardAPIUrl, + data: data, + successAction: ( response ) => { + console.log( data ); + console.log( response ); + if ( response.success ) { + } + }, + failAction: ( response ) => { + console.log( response ); + }, + } ); + } + }, + } ); + } ); +} diff --git a/assets/js/admin.js b/assets/js/scan-posts.js similarity index 64% rename from assets/js/admin.js rename to assets/js/scan-posts.js index 368dbfc2c..74a590de1 100644 --- a/assets/js/admin.js +++ b/assets/js/scan-posts.js @@ -1,47 +1,5 @@ -/** - * Loaded on edit-tags admin pages, this file contains the JavaScript for the ProgressPlanner plugin. - */ - /* global progressPlanner */ -/** - * A helper to make AJAX requests. - * - * @param {Object} params The callback parameters. - * @param {string} params.url The URL to send the request to. - * @param {Object} params.data The data to send with the request. - * @param {Function} params.successAction The callback to run on success. - * @param {Function} params.failAction The callback to run on failure. - */ -const progressPlannerAjaxRequest = ( { url, data, successAction, failAction } ) => { - const http = new XMLHttpRequest(); - http.open( 'POST', url, true ); - http.onreadystatechange = () => { - let response; - try { - response = JSON.parse( http.response ); - } catch ( e ) { - if ( http.readyState === 4 && http.status !== 200 ) { - // eslint-disable-next-line no-console - console.warn( http, e ); - return http.response; - } - } - if ( http.readyState === 4 && http.status === 200 ) { - return successAction ? successAction( response ) : response; - } - return failAction ? failAction( response ) : response; - }; - - const dataForm = new FormData(); - - // eslint-disable-next-line prefer-const - for ( let [ key, value ] of Object.entries( data ) ) { - dataForm.append( key, value ); - } - - http.send( dataForm ); -}; const progressPlannerTriggerScan = () => { document.getElementById( 'progress-planner-scan-progress' ).style.display = 'block'; @@ -75,6 +33,7 @@ const progressPlannerTriggerScan = () => { * The AJAX request to run. */ progressPlannerAjaxRequest( { + method: 'POST', url: progressPlanner.ajaxUrl, data: { action: 'progress_planner_scan_posts', @@ -124,6 +83,7 @@ progressPlannerDomReady( () => { // Make an AJAX request to reset the stats. progressPlannerAjaxRequest( { + method: 'POST', url: progressPlanner.ajaxUrl, data: { action: 'progress_planner_reset_stats', @@ -164,26 +124,3 @@ if ( document.getElementById( 'prpl-dev-stats-numbers' ) ) { } ); } -if ( document.getElementById( 'prpl-onboarding-form' ) ) { - document.getElementById( 'prpl-onboarding-form' ).addEventListener( 'submit', function( event ) { - event.preventDefault(); - const inputs = this.querySelectorAll( 'input' ); - const data = {}; - inputs.forEach( input => { - if ( input.name ) { - data[ input.name ] = input.value; - } - } ); - console.log( data ); - progressPlannerAjaxRequest( { - url: progressPlanner.onboardAPIUrl, - data: data, - successAction: ( response ) => { - console.log( response ); - if ( response.success ) { - // location.reload(); - } - }, - } ); - } ); -} diff --git a/includes/admin/class-page.php b/includes/admin/class-page.php index 567be0d28..7eac2b778 100644 --- a/includes/admin/class-page.php +++ b/includes/admin/class-page.php @@ -87,11 +87,30 @@ public static function enqueue_scripts() { false ); + // Enqueue the ajax-request helper. \wp_enqueue_script( - 'progress-planner-admin', - PROGRESS_PLANNER_URL . '/assets/js/admin.js', + 'progress-planner-ajax', + PROGRESS_PLANNER_URL . '/assets/js/ajax-request.js', [], - filemtime( PROGRESS_PLANNER_DIR . '/assets/js/admin.js' ), + filemtime( PROGRESS_PLANNER_DIR . '/assets/js/ajax-request.js' ), + true + ); + + // Enqueue the admin script to scan posts. + \wp_enqueue_script( + 'progress-planner-admin', + PROGRESS_PLANNER_URL . '/assets/js/scan-posts.js', + [ 'progress-planner-ajax' ], + filemtime( PROGRESS_PLANNER_DIR . '/assets/js/scan-posts.js' ), + true + ); + + // Enqueue the admin script to handle onboarding. + \wp_enqueue_script( + 'progress-planner-onboard', + PROGRESS_PLANNER_URL . '/assets/js/onboard.js', + [ 'progress-planner-ajax' ], + filemtime( PROGRESS_PLANNER_DIR . '/assets/js/onboard.js' ), true ); @@ -100,10 +119,11 @@ public static function enqueue_scripts() { 'progress-planner-admin', 'progressPlanner', [ - 'onboardAPIUrl' => Onboard::get_remote_url(), - 'ajaxUrl' => \admin_url( 'admin-ajax.php' ), - 'nonce' => \wp_create_nonce( 'progress_planner_scan' ), - 'l10n' => [ + 'onboardGetNonceURL' => Onboard::get_remote_nonce_url(), + 'onboardAPIUrl' => Onboard::get_remote_url(), + 'ajaxUrl' => \admin_url( 'admin-ajax.php' ), + 'nonce' => \wp_create_nonce( 'progress_planner_scan' ), + 'l10n' => [ 'resettingStats' => \esc_html__( 'Resetting stats...', 'progress-planner' ), ], ] diff --git a/includes/class-api.php b/includes/class-api.php index 74c5ff160..ec2529254 100644 --- a/includes/class-api.php +++ b/includes/class-api.php @@ -49,7 +49,7 @@ public function register_rest_endpoint() { 'args' => [ 'token' => [ 'required' => true, - 'validate_callback' => [ $this, 'validate_token' ], + 'validate_callback' => '__return_true' // TODO: Validate the token. ], ], ], @@ -57,17 +57,6 @@ public function register_rest_endpoint() { ); } - /** - * Validate the token. - * - * @param string $token The token. - * - * @return bool - */ - public function validate_token( $token ) { - return str_replace( 'token/', '', $token ) === self::get_api_token(); - } - /** * Receive the data from the client. * @@ -121,19 +110,4 @@ public function get_stats( \WP_REST_Request $request ) { return new \WP_REST_Response( $data ); } - - /** - * Get the API token. - * - * @return string - */ - public static function get_api_token() { - $token = Settings::get( 'api_token', false ); - - if ( ! $token ) { - $token = \wp_generate_password( 32, false ); - Settings::set( 'api_token', $token ); - } - return $token; - } } diff --git a/includes/class-onboard.php b/includes/class-onboard.php index ce496ef6d..112394b6e 100644 --- a/includes/class-onboard.php +++ b/includes/class-onboard.php @@ -54,17 +54,6 @@ public static function the_form() { > - - -

@@ -27,8 +25,6 @@ - Name field (optional, placeholder prepopulated from their profile) - Consent checkbox to send the data to the remote server - Submit button: Send the data and start scanning existing content to calculate the user's activity score as a baseline. - - DEV NOTE: REST-API endpoint to get the data: From a7ab89e8c69310f6fc38875765265fdd8e1ed15f Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 1 Apr 2024 11:26:02 +0300 Subject: [PATCH 275/490] split functions --- assets/js/onboard.js | 74 +++++++++++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 28 deletions(-) diff --git a/assets/js/onboard.js b/assets/js/onboard.js index e022906fa..be406ea77 100644 --- a/assets/js/onboard.js +++ b/assets/js/onboard.js @@ -1,5 +1,50 @@ /* global progressPlanner */ +/** + * Make the AJAX request. + * + * @param {Object} data The data to send with the request. + */ +const progressPlannerAjaxAPIRequest = ( data ) => { + progressPlannerAjaxRequest( { + method: 'POST', + url: progressPlanner.onboardAPIUrl, + data: data, + successAction: ( response ) => { + console.log( data ); + console.log( response ); + if ( response.success ) { + } + }, + failAction: ( response ) => { + console.log( response ); + }, + } ); +}; + +/** + * Make the AJAX request. + * + * @param {Object} data The data to send with the request. + */ +const progressPlannerOnboardCall = ( data ) => { + progressPlannerAjaxRequest( { + method: 'POST', + url: progressPlanner.onboardGetNonceURL, + data: data, + successAction: ( response ) => { + if ( 'ok' === response.status ) { + + // Add the nonce to our data object. + data.nonce = response.nonce; +console.log(data); + // Make the request to the API. + progressPlannerAjaxAPIRequest( data ); + } + }, + } ); +}; + if ( document.getElementById( 'prpl-onboarding-form' ) ) { document.getElementById( 'prpl-onboarding-form' ).addEventListener( 'submit', function( event ) { event.preventDefault(); @@ -15,33 +60,6 @@ if ( document.getElementById( 'prpl-onboarding-form' ) ) { // Make a request to get the nonce. // Once the nonce is received, make a request to the API. - progressPlannerAjaxRequest( { - method: 'POST', - url: progressPlanner.onboardGetNonceURL, - data: data, - successAction: ( response ) => { - if ( 'ok' === response.status ) { - - // Add the nonce to our data object. - data.nonce = response.nonce; -console.log(data); - // Make the request to the API. - progressPlannerAjaxRequest( { - method: 'POST', - url: progressPlanner.onboardAPIUrl, - data: data, - successAction: ( response ) => { - console.log( data ); - console.log( response ); - if ( response.success ) { - } - }, - failAction: ( response ) => { - console.log( response ); - }, - } ); - } - }, - } ); + progressPlannerOnboardCall( data ); } ); } From 2e6049ed03f8fb7e3aac701a88e3789ff32b118b Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 1 Apr 2024 11:59:57 +0300 Subject: [PATCH 276/490] Store the license. --- assets/js/onboard.js | 28 +++++++++++++++++--------- includes/actions/class-content.php | 4 ++-- includes/admin/class-page.php | 10 +++++----- includes/class-base.php | 4 ++++ includes/class-onboard.php | 32 ++++++++++++++++++++++++++++++ 5 files changed, 62 insertions(+), 16 deletions(-) diff --git a/assets/js/onboard.js b/assets/js/onboard.js index be406ea77..203cfca07 100644 --- a/assets/js/onboard.js +++ b/assets/js/onboard.js @@ -11,10 +11,20 @@ const progressPlannerAjaxAPIRequest = ( data ) => { url: progressPlanner.onboardAPIUrl, data: data, successAction: ( response ) => { - console.log( data ); - console.log( response ); - if ( response.success ) { - } + // Make a local request to save the response data. + progressPlannerAjaxRequest( { + method: 'POST', + url: progressPlanner.ajaxUrl, + data: { + action: 'progress_planner_save_onboard_data', + _ajax_nonce: progressPlanner.nonce, + key: response.license_key, + }, + successAction: ( response ) => { + // TODO: Print a link in the UI so the user can directly go to change their password. + console.log( response ); + }, + } ); }, failAction: ( response ) => { console.log( response ); @@ -25,19 +35,22 @@ const progressPlannerAjaxAPIRequest = ( data ) => { /** * Make the AJAX request. * + * Make a request to get the nonce. + * Once the nonce is received, make a request to the API. + * * @param {Object} data The data to send with the request. */ const progressPlannerOnboardCall = ( data ) => { progressPlannerAjaxRequest( { method: 'POST', - url: progressPlanner.onboardGetNonceURL, + url: progressPlanner.onboardNonceURL, data: data, successAction: ( response ) => { if ( 'ok' === response.status ) { // Add the nonce to our data object. data.nonce = response.nonce; -console.log(data); + // Make the request to the API. progressPlannerAjaxAPIRequest( data ); } @@ -57,9 +70,6 @@ if ( document.getElementById( 'prpl-onboarding-form' ) ) { data[ input.name ] = input.value; } } ); - - // Make a request to get the nonce. - // Once the nonce is received, make a request to the API. progressPlannerOnboardCall( data ); } ); } diff --git a/includes/actions/class-content.php b/includes/actions/class-content.php index d4d1843fc..7a6e22f90 100644 --- a/includes/actions/class-content.php +++ b/includes/actions/class-content.php @@ -371,7 +371,7 @@ public static function reset_stats() { */ public function ajax_scan() { // Check the nonce. - if ( ! \check_ajax_referer( 'progress_planner_scan', 'nonce', false ) ) { + if ( ! \check_ajax_referer( 'progress_planner', 'nonce', false ) ) { \wp_send_json_error( [ 'message' => \esc_html__( 'Invalid nonce.', 'progress-planner' ) ] ); } @@ -397,7 +397,7 @@ public function ajax_scan() { */ public function ajax_reset_stats() { // Check the nonce. - if ( ! \check_ajax_referer( 'progress_planner_scan', 'nonce', false ) ) { + if ( ! \check_ajax_referer( 'progress_planner', 'nonce', false ) ) { \wp_send_json_error( [ 'message' => \esc_html__( 'Invalid nonce.', 'progress-planner' ) ] ); } diff --git a/includes/admin/class-page.php b/includes/admin/class-page.php index 7eac2b778..5f0b08132 100644 --- a/includes/admin/class-page.php +++ b/includes/admin/class-page.php @@ -119,11 +119,11 @@ public static function enqueue_scripts() { 'progress-planner-admin', 'progressPlanner', [ - 'onboardGetNonceURL' => Onboard::get_remote_nonce_url(), - 'onboardAPIUrl' => Onboard::get_remote_url(), - 'ajaxUrl' => \admin_url( 'admin-ajax.php' ), - 'nonce' => \wp_create_nonce( 'progress_planner_scan' ), - 'l10n' => [ + 'onboardNonceURL' => Onboard::get_remote_nonce_url(), + 'onboardAPIUrl' => Onboard::get_remote_url(), + 'ajaxUrl' => \admin_url( 'admin-ajax.php' ), + 'nonce' => \wp_create_nonce( 'progress_planner' ), + 'l10n' => [ 'resettingStats' => \esc_html__( 'Resetting stats...', 'progress-planner' ), ], ] diff --git a/includes/class-base.php b/includes/class-base.php index e8a6fe22a..77b9eba19 100644 --- a/includes/class-base.php +++ b/includes/class-base.php @@ -103,6 +103,10 @@ public function init() { new Badge_Super_Site_Specialist(); new API(); + + if ( ! Settings::get( 'license_key' ) ) { + new Onboard(); + } } /** diff --git a/includes/class-onboard.php b/includes/class-onboard.php index 112394b6e..dcd03c491 100644 --- a/includes/class-onboard.php +++ b/includes/class-onboard.php @@ -21,6 +21,13 @@ class Onboard { */ const REMOTE_URL = 'https://progressplanner.com'; + /** + * Constructor. + */ + public function __construct() { + \add_action( 'wp_ajax_progress_planner_save_onboard_data', [ $this, 'save_onboard_response' ] ); + } + /** * The onboarding form. * @@ -68,6 +75,31 @@ class="button button-primary" \esc_html__( 'Invalid nonce.', 'progress-planner' ) ] ); + } + + if ( ! isset( $_POST['license_key'] ) ) { + \wp_send_json_error( [ 'message' => \esc_html__( 'Missing data.', 'progress-planner' ) ] ); + } + + $license_key = \sanitize_text_field( wp_unslash( $_POST['license_key'] ) ); + + Settings::set( [ 'license_key' ], $license_key ); + \wp_send_json_success( + [ + 'message' => \esc_html__( 'Onboarding data saved.', 'progress-planner' ), + ] + ); + } + /** * Get the remote nonce URL. * From 5ac376a6e49e48238213d6105c03b75649db03a9 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 1 Apr 2024 13:05:15 +0300 Subject: [PATCH 277/490] Fix saving the license key. --- includes/class-onboard.php | 6 +++--- views/welcome.php | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/includes/class-onboard.php b/includes/class-onboard.php index dcd03c491..ffef30855 100644 --- a/includes/class-onboard.php +++ b/includes/class-onboard.php @@ -86,13 +86,13 @@ public function save_onboard_response() { \wp_send_json_error( [ 'message' => \esc_html__( 'Invalid nonce.', 'progress-planner' ) ] ); } - if ( ! isset( $_POST['license_key'] ) ) { + if ( ! isset( $_POST['key'] ) ) { \wp_send_json_error( [ 'message' => \esc_html__( 'Missing data.', 'progress-planner' ) ] ); } - $license_key = \sanitize_text_field( wp_unslash( $_POST['license_key'] ) ); + $license_key = \sanitize_text_field( wp_unslash( $_POST['key'] ) ); - Settings::set( [ 'license_key' ], $license_key ); + Settings::set( 'license_key', $license_key ); \wp_send_json_success( [ 'message' => \esc_html__( 'Onboarding data saved.', 'progress-planner' ), diff --git a/views/welcome.php b/views/welcome.php index 0e90f8d81..e8f08416e 100644 --- a/views/welcome.php +++ b/views/welcome.php @@ -10,8 +10,10 @@ use ProgressPlanner\Settings; // If the user is already registered, do not show the welcome widget. -if ( Settings::get( 'registered' ) ) { - return; +if ( Settings::get( 'license_key' ) ) { + // TODO: This is commented-out just for now to facilitate building the welcome box. + // Once we're done, the line should be uncommented. + // return; } ?> From c05cc375aec5416b0d610de14681087dfa892569 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 1 Apr 2024 14:19:04 +0300 Subject: [PATCH 278/490] WIP - there's still an error 400 --- assets/css/admin.css | 4 ++++ assets/js/admin.js | 12 ++++++++++ assets/js/onboard.js | 5 +++++ assets/js/scan-posts.js | 38 -------------------------------- includes/admin/class-page.php | 40 ++++++++++++++++++++-------------- includes/class-api.php | 3 +-- includes/class-onboard.php | 20 ++++++++++++++--- views/admin-page-form-scan.php | 17 --------------- views/welcome.php | 12 ---------- 9 files changed, 63 insertions(+), 88 deletions(-) create mode 100644 assets/js/admin.js delete mode 100644 views/admin-page-form-scan.php diff --git a/assets/css/admin.css b/assets/css/admin.css index 135e1b98e..61bc2faa8 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -415,3 +415,7 @@ display: block; margin-bottom: 0.5em; } + +#progress-planner-onboard-responses ul li { + display: none; +} diff --git a/assets/js/admin.js b/assets/js/admin.js new file mode 100644 index 000000000..5d8353222 --- /dev/null +++ b/assets/js/admin.js @@ -0,0 +1,12 @@ +document.getElementById( 'prpl-select-range' ).addEventListener( 'change', function() { + const range = this.value; + const url = new URL( window.location.href ); + url.searchParams.set( 'range', range ); + window.location.href = url.href; +} ); +document.getElementById( 'prpl-select-frequency' ).addEventListener( 'change', function() { + const frequency = this.value; + const url = new URL( window.location.href ); + url.searchParams.set( 'frequency', frequency ); + window.location.href = url.href; +} ); diff --git a/assets/js/onboard.js b/assets/js/onboard.js index 203cfca07..7760280d1 100644 --- a/assets/js/onboard.js +++ b/assets/js/onboard.js @@ -21,6 +21,9 @@ const progressPlannerAjaxAPIRequest = ( data ) => { key: response.license_key, }, successAction: ( response ) => { + // Start scanning posts. + document.querySelector( '#progress-planner-onboard-responses .scanning-posts' ).style.display = 'list-item'; + progressPlannerTriggerScan(); // TODO: Print a link in the UI so the user can directly go to change their password. console.log( response ); }, @@ -41,6 +44,7 @@ const progressPlannerAjaxAPIRequest = ( data ) => { * @param {Object} data The data to send with the request. */ const progressPlannerOnboardCall = ( data ) => { + document.querySelector( '#progress-planner-onboard-responses .registering-site' ).style.display = 'list-item'; progressPlannerAjaxRequest( { method: 'POST', url: progressPlanner.onboardNonceURL, @@ -61,6 +65,7 @@ const progressPlannerOnboardCall = ( data ) => { if ( document.getElementById( 'prpl-onboarding-form' ) ) { document.getElementById( 'prpl-onboarding-form' ).addEventListener( 'submit', function( event ) { event.preventDefault(); + document.querySelector( '#prpl-onboarding-form input[type="submit"]' ).disabled = true; const inputs = this.querySelectorAll( 'input' ); // Build the data object. diff --git a/assets/js/scan-posts.js b/assets/js/scan-posts.js index 74a590de1..8c1bf6cbc 100644 --- a/assets/js/scan-posts.js +++ b/assets/js/scan-posts.js @@ -61,17 +61,6 @@ progressPlannerDomReady( () => { const scanForm = document.getElementById( 'progress-planner-scan' ); const resetForm = document.getElementById( 'progress-planner-stats-reset' ); - /** - * Add an event listener for the scan form. - */ - if ( scanForm ) { - scanForm.addEventListener( 'submit', ( e ) => { - e.preventDefault(); - scanForm.querySelector( 'input[type="submit"]' ).disabled = true; - progressPlannerTriggerScan(); - } ); - } - /** * Add an event listener for the reset form. */ @@ -97,30 +86,3 @@ progressPlannerDomReady( () => { } ); } } ); - -document.getElementById( 'prpl-select-range' ).addEventListener( 'change', function() { - const range = this.value; - const url = new URL( window.location.href ); - url.searchParams.set( 'range', range ); - window.location.href = url.href; -} ); -document.getElementById( 'prpl-select-frequency' ).addEventListener( 'change', function() { - const frequency = this.value; - const url = new URL( window.location.href ); - url.searchParams.set( 'frequency', frequency ); - window.location.href = url.href; -} ); - -if ( document.getElementById( 'prpl-dev-stats-numbers' ) ) { - document.getElementById( 'prpl-dev-stats-numbers' ).addEventListener( 'submit', function( event ) { - event.preventDefault(); - const inputs = this.querySelectorAll( 'input' ); - const url = new URL( window.location.href ); - - inputs.forEach( input => { - url.searchParams.set( input.name, input.value ); - } ); - window.location.href = url.href; - } ); -} - diff --git a/includes/admin/class-page.php b/includes/admin/class-page.php index 5f0b08132..22b088d02 100644 --- a/includes/admin/class-page.php +++ b/includes/admin/class-page.php @@ -88,7 +88,7 @@ public static function enqueue_scripts() { ); // Enqueue the ajax-request helper. - \wp_enqueue_script( + \wp_register_script( 'progress-planner-ajax', PROGRESS_PLANNER_URL . '/assets/js/ajax-request.js', [], @@ -97,8 +97,8 @@ public static function enqueue_scripts() { ); // Enqueue the admin script to scan posts. - \wp_enqueue_script( - 'progress-planner-admin', + \wp_register_script( + 'progress-planner-scanner', PROGRESS_PLANNER_URL . '/assets/js/scan-posts.js', [ 'progress-planner-ajax' ], filemtime( PROGRESS_PLANNER_DIR . '/assets/js/scan-posts.js' ), @@ -109,25 +109,33 @@ public static function enqueue_scripts() { \wp_enqueue_script( 'progress-planner-onboard', PROGRESS_PLANNER_URL . '/assets/js/onboard.js', - [ 'progress-planner-ajax' ], + [ 'progress-planner-ajax', 'progress-planner-scanner' ], filemtime( PROGRESS_PLANNER_DIR . '/assets/js/onboard.js' ), true ); - // Localize the script. - \wp_localize_script( + // Enqueue the admin script for the page. + \wp_enqueue_script( 'progress-planner-admin', - 'progressPlanner', - [ - 'onboardNonceURL' => Onboard::get_remote_nonce_url(), - 'onboardAPIUrl' => Onboard::get_remote_url(), - 'ajaxUrl' => \admin_url( 'admin-ajax.php' ), - 'nonce' => \wp_create_nonce( 'progress_planner' ), - 'l10n' => [ - 'resettingStats' => \esc_html__( 'Resetting stats...', 'progress-planner' ), - ], - ] + PROGRESS_PLANNER_URL . '/assets/js/admin.js', + [], + filemtime( PROGRESS_PLANNER_DIR . '/assets/js/admin.js' ), + true ); + + $localize_data = [ + 'onboardNonceURL' => Onboard::get_remote_nonce_url(), + 'onboardAPIUrl' => Onboard::get_remote_url(), + 'ajaxUrl' => \admin_url( 'admin-ajax.php' ), + 'nonce' => \wp_create_nonce( 'progress_planner' ), + 'l10n' => [ + 'resettingStats' => \esc_html__( 'Resetting stats...', 'progress-planner' ), + ], + ]; + + // Localize the scripts. + \wp_localize_script( 'progress-planner-onboard', 'progressPlanner', $localize_data ); + \wp_localize_script( 'progress-planner-admin', 'progressPlanner', $localize_data ); } /** diff --git a/includes/class-api.php b/includes/class-api.php index ec2529254..9d20a38f3 100644 --- a/includes/class-api.php +++ b/includes/class-api.php @@ -13,7 +13,6 @@ namespace ProgressPlanner; use ProgressPlanner\Badges; -use ProgressPlanner\Settings; use ProgressPlanner\Badges\Badge\Wonderful_Writer as Badge_Wonderful_Writer; use ProgressPlanner\Badges\Badge\Awesome_Author as Badge_Awesome_Author; use ProgressPlanner\Badges\Badge\Notorious_Novelist as Badge_Notorious_Novelist; @@ -49,7 +48,7 @@ public function register_rest_endpoint() { 'args' => [ 'token' => [ 'required' => true, - 'validate_callback' => '__return_true' // TODO: Validate the token. + 'validate_callback' => '__return_true', // TODO: Validate the token. ], ], ], diff --git a/includes/class-onboard.php b/includes/class-onboard.php index ffef30855..89b31435e 100644 --- a/includes/class-onboard.php +++ b/includes/class-onboard.php @@ -45,14 +45,14 @@ public static function the_form() { value="user_email ); ?>" > -
Date: Tue, 2 Apr 2024 11:58:02 +0300 Subject: [PATCH 280/490] Validate the token when getting stats remotely --- includes/class-api.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/includes/class-api.php b/includes/class-api.php index 9d20a38f3..533d20873 100644 --- a/includes/class-api.php +++ b/includes/class-api.php @@ -48,7 +48,7 @@ public function register_rest_endpoint() { 'args' => [ 'token' => [ 'required' => true, - 'validate_callback' => '__return_true', // TODO: Validate the token. + 'validate_callback' => [ $this, 'validate_token' ], ], ], ], @@ -109,4 +109,15 @@ public function get_stats( \WP_REST_Request $request ) { return new \WP_REST_Response( $data ); } + + /** + * Validate the token. + * + * @param string $token The token. + */ + public function validate_token( $token ) { + $token = str_replace( 'token/', '', $token ); + + return $token === Settings::get( 'license_key' ); + } } From 0cf5fa12e6cece824baa73cbc5c92d4e7dd02eee Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 2 Apr 2024 11:58:13 +0300 Subject: [PATCH 281/490] this is done --- views/welcome.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/views/welcome.php b/views/welcome.php index 2c821adca..ee131c5b5 100644 --- a/views/welcome.php +++ b/views/welcome.php @@ -11,9 +11,7 @@ // If the user is already registered, do not show the welcome widget. if ( Settings::get( 'license_key' ) ) { - // TODO: This is commented-out just for now to facilitate building the welcome box. - // Once we're done, the line should be uncommented. - // return; + return; } ?> From 118ca348414591db0aa0e7f177fb188cff0c3da1 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 2 Apr 2024 12:15:46 +0300 Subject: [PATCH 282/490] Rename class --- includes/class-base.php | 4 ++-- includes/{class-api.php => class-rest-api.php} | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) rename includes/{class-api.php => class-rest-api.php} (98%) diff --git a/includes/class-base.php b/includes/class-base.php index 77b9eba19..1e1fb5934 100644 --- a/includes/class-base.php +++ b/includes/class-base.php @@ -19,7 +19,7 @@ use ProgressPlanner\Badges\Badge\Progress_Professional as Badge_Progress_Professional; use ProgressPlanner\Badges\Badge\Maintenance_Maniac as Badge_Maintenance_Maniac; use ProgressPlanner\Badges\Badge\Super_Site_Specialist as Badge_Super_Site_Specialist; -use ProgressPlanner\API; +use ProgressPlanner\Rest_API; /** * Main plugin class. @@ -102,7 +102,7 @@ public function init() { new Badge_Maintenance_Maniac(); new Badge_Super_Site_Specialist(); - new API(); + new Rest_API(); if ( ! Settings::get( 'license_key' ) ) { new Onboard(); diff --git a/includes/class-api.php b/includes/class-rest-api.php similarity index 98% rename from includes/class-api.php rename to includes/class-rest-api.php index 533d20873..78dbdff7f 100644 --- a/includes/class-api.php +++ b/includes/class-rest-api.php @@ -1,6 +1,6 @@ /wp-json/progress-planner/v1/get-stats/token/ @@ -22,9 +22,9 @@ /** - * API class. + * Rest_API class. */ -class API { +class Rest_API { /** * Constructor. */ From c2dfa556ef58fba1a490bc9bcd4beeb2858f73f2 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 2 Apr 2024 12:22:46 +0300 Subject: [PATCH 283/490] cleanup for badges - remove categories --- includes/badges/class-badge-content.php | 10 +--------- includes/badges/class-badge-maintenance.php | 7 ------- includes/badges/class-badge.php | 8 -------- includes/widgets/class-badges-progress.php | 12 ++++++------ 4 files changed, 7 insertions(+), 30 deletions(-) diff --git a/includes/badges/class-badge-content.php b/includes/badges/class-badge-content.php index 7f559922e..7756a6e8b 100644 --- a/includes/badges/class-badge-content.php +++ b/includes/badges/class-badge-content.php @@ -12,12 +12,4 @@ /** * Badge class. */ -abstract class Badge_Content extends Badge { - - /** - * The badge category. - * - * @var string - */ - protected $category = 'content_writing'; -} +abstract class Badge_Content extends Badge {} diff --git a/includes/badges/class-badge-maintenance.php b/includes/badges/class-badge-maintenance.php index fdfe4fd83..4bf953f17 100644 --- a/includes/badges/class-badge-maintenance.php +++ b/includes/badges/class-badge-maintenance.php @@ -16,13 +16,6 @@ */ abstract class Badge_Maintenance extends Badge { - /** - * The badge category. - * - * @var string - */ - protected $category = 'streak_any_task'; - /** * Get a recurring goal for any type of weekly activity. * diff --git a/includes/badges/class-badge.php b/includes/badges/class-badge.php index e32af2a6c..cbfe79061 100644 --- a/includes/badges/class-badge.php +++ b/includes/badges/class-badge.php @@ -22,13 +22,6 @@ abstract class Badge { */ protected $id; - /** - * The badge category. - * - * @var string - */ - protected $category; - /** * Constructor. */ @@ -43,7 +36,6 @@ public function register_badge() { Badges::register_badge( $this->id, [ - 'category' => $this->category, 'name' => $this->get_name(), 'icons-svg' => $this->get_icons_svg(), 'progress_callback' => [ $this, 'progress_callback' ], diff --git a/includes/widgets/class-badges-progress.php b/includes/widgets/class-badges-progress.php index b89e1a4e5..9366e2c5e 100644 --- a/includes/widgets/class-badges-progress.php +++ b/includes/widgets/class-badges-progress.php @@ -37,13 +37,13 @@ protected function the_content() { - -
- + $group_badges ) : ?> +
+ -

+

From 69dbab3804d78097081f1da27c334bba78710e34 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 2 Apr 2024 12:43:10 +0300 Subject: [PATCH 284/490] Don't scan JS files with PHPCS --- phpcs.xml.dist | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 13839c80c..856de2283 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -21,8 +21,8 @@ /coverage/* - - *.min.js + + *.js From b5d3603f50d27bace783f9086bc476027e430594 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 2 Apr 2024 12:58:41 +0300 Subject: [PATCH 285/490] Allow querying by id --- includes/class-query.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/includes/class-query.php b/includes/class-query.php index a57a00c30..5a795e07b 100644 --- a/includes/class-query.php +++ b/includes/class-query.php @@ -105,6 +105,7 @@ public function query_activities( $args, $return_type = 'ACTIVITIES' ) { global $wpdb; $defaults = [ + 'id' => null, 'start_date' => null, 'end_date' => null, 'category' => null, @@ -121,6 +122,10 @@ public function query_activities( $args, $return_type = 'ACTIVITIES' ) { if ( false === $results ) { $where_args = []; $prepare_args = []; + if ( $args['id'] !== null ) { + $where_args[] = 'id = %d'; + $prepare_args[] = $args['id']; + } if ( $args['start_date'] !== null ) { $where_args[] = 'date >= %s'; $prepare_args[] = ( $args['start_date'] instanceof \Datetime ) From f8891d16f57b6bdae1347724d841042970e6fad1 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 2 Apr 2024 12:58:54 +0300 Subject: [PATCH 286/490] Add tests for activity --- tests/phpunit/test-class-activity.php | 108 ++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 tests/phpunit/test-class-activity.php diff --git a/tests/phpunit/test-class-activity.php b/tests/phpunit/test-class-activity.php new file mode 100644 index 000000000..7c6dcf4cb --- /dev/null +++ b/tests/phpunit/test-class-activity.php @@ -0,0 +1,108 @@ +activity = new Activity(); + $this->activity->set_category( 'test_category' ); + $this->activity->set_type( 'test_type' ); + $this->activity->set_date( new \DateTime() ); + $this->activity->set_data_id( 100 ); + $this->activity->set_user_id( 1 ); + } + + /** + * Test the get_category method. + * + * @return void + */ + public function test_get_category() { + $this->assertEquals( 'test_category', $this->activity->get_category() ); + } + + /** + * Test the get_type method. + * + * @return void + */ + public function test_get_type() { + $this->assertEquals( 'test_type', $this->activity->get_type() ); + } + + /** + * Test the get_date method. + * + * @return void + */ + public function test_get_date() { + $this->assertInstanceOf( \DateTime::class, $this->activity->get_date() ); + } + + /** + * Test the get_data_id method. + * + * @return void + */ + public function test_get_data_id() { + $this->assertEquals( 100, $this->activity->get_data_id() ); + } + + /** + * Test the get_user_id method. + * + * @return void + */ + public function test_get_user_id() { + $this->assertEquals( 1, $this->activity->get_user_id() ); + } + + /** + * Test saving the activity. + * + * @return void + */ + public function test_save() { + $this->activity->save(); + + $activity = \progress_planner()->get_query()->query_activities( + [ + 'category' => $this->activity->get_category(), + 'type' => $this->activity->get_type(), + 'user_id' => 1, + ] + )[0]; + + $this->assertEquals( $this->activity->get_category(), $activity->get_category() ); + $this->assertEquals( $this->activity->get_type(), $activity->get_type() ); + $this->assertEquals( $this->activity->get_date()->format( 'Y-m-d' ), $activity->get_date()->format( 'Y-m-d' ) ); + $this->assertEquals( $this->activity->get_data_id(), $activity->get_data_id() ); + $this->assertEquals( $this->activity->get_user_id(), $activity->get_user_id() ); + } +} From 054d581cbc49b32f62d6ba775a14e53832e50828 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 2 Apr 2024 13:01:32 +0300 Subject: [PATCH 287/490] Cleanup --- includes/class-onboard.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/includes/class-onboard.php b/includes/class-onboard.php index f1dc86c1a..db4d1aa86 100644 --- a/includes/class-onboard.php +++ b/includes/class-onboard.php @@ -45,14 +45,6 @@ public static function the_form() { value="user_email ); ?>" > -
Date: Wed, 3 Apr 2024 14:27:33 +0300 Subject: [PATCH 304/490] Abstract big-counters rendering --- .../widgets/class-personal-record-content.php | 9 +------- includes/widgets/class-plugins.php | 9 +------- .../class-published-content-density.php | 9 +------- includes/widgets/class-published-content.php | 9 +------- includes/widgets/class-published-words.php | 9 +------- includes/widgets/class-widget.php | 21 +++++++++++++++++++ 6 files changed, 26 insertions(+), 40 deletions(-) diff --git a/includes/widgets/class-personal-record-content.php b/includes/widgets/class-personal-record-content.php index 90d6d31bb..383cce460 100644 --- a/includes/widgets/class-personal-record-content.php +++ b/includes/widgets/class-personal-record-content.php @@ -33,14 +33,7 @@ protected function the_content() { $record = $this->personal_record_callback(); ?>
-
- - - - - - -
+ render_big_counter( $record['max_streak'], __( 'personal record', 'progress-planner' ) ); ?>

diff --git a/includes/widgets/class-plugins.php b/includes/widgets/class-plugins.php index dbc887d73..502ec3cf9 100644 --- a/includes/widgets/class-plugins.php +++ b/includes/widgets/class-plugins.php @@ -35,14 +35,7 @@ protected function the_content() { ?>

-
- - - - - - -
+ render_big_counter( $plugins_count, __( 'plugins', 'progress-planner' ) ); ?>

diff --git a/includes/widgets/class-published-content-density.php b/includes/widgets/class-published-content-density.php index f64195b2f..a4b986e53 100644 --- a/includes/widgets/class-published-content-density.php +++ b/includes/widgets/class-published-content-density.php @@ -32,14 +32,7 @@ protected function the_content() { ?>
-
- - get_weekly_activities_density() ) ); ?> - - - - -
+ render_big_counter( $this->get_weekly_activities_density(), __( 'content density', 'progress-planner' ) ); ?>

-
- - - - - - -
+ render_big_counter( array_sum( $stats['weekly'] ), __( 'content published', 'progress-planner' ) ); ?>

diff --git a/includes/widgets/class-published-words.php b/includes/widgets/class-published-words.php index 240090285..544d3cca3 100644 --- a/includes/widgets/class-published-words.php +++ b/includes/widgets/class-published-words.php @@ -31,14 +31,7 @@ protected function the_content() { ?>

-
- - get_weekly_words() ) ); ?> - - - - -
+ render_big_counter( $this->get_weekly_words(), __( 'words written', 'progress-planner' ) ); ?>

get_weekly_words() ) : ?> diff --git a/includes/widgets/class-widget.php b/includes/widgets/class-widget.php index 3dd13482f..342be6185 100644 --- a/includes/widgets/class-widget.php +++ b/includes/widgets/class-widget.php @@ -63,6 +63,27 @@ protected function render() { echo '

'; } + /** + * Render a big counter. + * + * @param string $number The number to display. + * @param string $text The text to display. + * + * @return void + */ + protected function render_big_counter( $number, $text ) { + ?> +
+ + + + + + +
+ Date: Thu, 4 Apr 2024 10:49:11 +0300 Subject: [PATCH 305/490] Avoid duplicate labels in charts x-axis --- includes/class-chart.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/includes/class-chart.php b/includes/class-chart.php index 92bdbff65..d74a12c88 100644 --- a/includes/class-chart.php +++ b/includes/class-chart.php @@ -237,10 +237,25 @@ public function render_chart_js( $id, $type, $data, $options = [] ) {
Date: Thu, 4 Apr 2024 12:02:40 +0300 Subject: [PATCH 306/490] tweaks for the what's new widget --- includes/widgets/class-whats-new.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/includes/widgets/class-whats-new.php b/includes/widgets/class-whats-new.php index 060c62276..cdc6dafe6 100644 --- a/includes/widgets/class-whats-new.php +++ b/includes/widgets/class-whats-new.php @@ -46,11 +46,17 @@ public function the_content() {

- +

+
+

+ + + +

Date: Thu, 4 Apr 2024 13:05:56 +0300 Subject: [PATCH 307/490] delete workflows not YET used --- .github/workflows/deploy.yml | 19 ------------------- .github/workflows/playground.yml | 16 ---------------- .github/workflows/wp-version-checker.yml | 20 -------------------- 3 files changed, 55 deletions(-) delete mode 100644 .github/workflows/deploy.yml delete mode 100644 .github/workflows/playground.yml delete mode 100644 .github/workflows/wp-version-checker.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index a007d1c66..000000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: "Deploy to WordPress.org" - -on: - push: - tags: - - "v*" - -jobs: - tag: - name: New tag - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@main - - name: WordPress Plugin Deploy - uses: 10up/action-wordpress-plugin-deploy@stable - env: - SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} - SVN_USERNAME: ${{ secrets.SVN_USERNAME }} - SLUG: fewer-tags diff --git a/.github/workflows/playground.yml b/.github/workflows/playground.yml deleted file mode 100644 index dfd05228e..000000000 --- a/.github/workflows/playground.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: Playground Comment - -on: - pull_request: - -jobs: - test: - runs-on: ubuntu-latest - permissions: - pull-requests: write - steps: - - uses: mshick/add-pr-comment@v2 - with: - message: | - **Test on Playground** - [Test this pull request on the Playground](https://playground.wordpress.net/#{"landingPage":"/wp-admin/edit-tags.php?taxonomy=post_tag","features":{"networking":true},"steps":[{"step":"defineWpConfigConsts","consts":{"IS_PLAYGROUND_PREVIEW":true}},{"step":"login","username":"admin","password":"password"},{"step":"installPlugin","pluginZipFile":{"resource":"url","url":"https://bypass-cors.altha.workers.dev/${{ github.server_url }}/${{ github.repository }}/archive/${{ github.sha }}.zip"},"options":{"activate":true}}]}) diff --git a/.github/workflows/wp-version-checker.yml b/.github/workflows/wp-version-checker.yml deleted file mode 100644 index 8cad49afd..000000000 --- a/.github/workflows/wp-version-checker.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: "WordPress version checker" -on: - push: - branches: - - develop - - main - schedule: - - cron: '0 0 * * *' - -permissions: - issues: write - -jobs: - wordpress-version-checker: - runs-on: ubuntu-latest - steps: - - name: WordPress version checker - uses: skaut/wordpress-version-checker@v2.0.0 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} From f73f33bc7afad82b64caa4f881b4d85d73baf423 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 4 Apr 2024 13:36:25 +0300 Subject: [PATCH 308/490] Redirect to plugin page on activation --- assets/css/admin.css | 4 ++++ includes/class-base.php | 6 +++--- includes/class-onboard.php | 24 ++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/assets/css/admin.css b/assets/css/admin.css index 135e1b98e..617f0aa86 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -207,6 +207,10 @@ \*------------------------------------*/ .prpl-widget-wrapper.prpl-welcome { margin-bottom: var(--prpl-gap); + padding: calc(var(--prpl-gap) * 1.5); + background: var(--prpl-background-purple); + border: none; + box-shadow: 0 0 10px var(--prpl-color-gray-2) } /*------------------------------------*\ diff --git a/includes/class-base.php b/includes/class-base.php index 6118b1419..3bd89a31b 100644 --- a/includes/class-base.php +++ b/includes/class-base.php @@ -95,11 +95,11 @@ public function init() { new Badge_Maintenance_Maniac(); new Badge_Super_Site_Specialist(); + // REST API. new Rest_API(); - if ( ! Settings::get( 'license_key' ) ) { - new Onboard(); - } + // Onboarding. + new Onboard(); } /** diff --git a/includes/class-onboard.php b/includes/class-onboard.php index a70e8239b..4fc49655b 100644 --- a/includes/class-onboard.php +++ b/includes/class-onboard.php @@ -25,9 +25,33 @@ class Onboard { * Constructor. */ public function __construct() { + if ( Settings::get( 'license_key' ) ) { + return; + } + + // Redirect on plugin activation. + \add_action( 'activated_plugin', [ $this, 'on_activate_plugin' ], 10 ); + + // Handle saving data from the onboarding form response. \add_action( 'wp_ajax_progress_planner_save_onboard_data', [ $this, 'save_onboard_response' ] ); } + /** + * On plugin activation. + * + * @param string $plugin The plugin file. + * + * @return void + */ + public function on_activate_plugin( $plugin ) { + if ( 'progress-planner/progress-planner.php' !== $plugin ) { + return; + } + + \wp_safe_redirect( admin_url( 'admin.php?page=progress-planner' ) ); + exit; + } + /** * The onboarding form. * From d4988f247737d065fbceb8909e37392dc3195802 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 4 Apr 2024 13:47:40 +0300 Subject: [PATCH 309/490] Add uninstall routine to cleanup the database --- uninstall.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 uninstall.php diff --git a/uninstall.php b/uninstall.php new file mode 100644 index 000000000..4c1cbbbca --- /dev/null +++ b/uninstall.php @@ -0,0 +1,30 @@ +query( + $wpdb->prepare( + // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnsupportedIdentifierPlaceholder, WordPress.DB.DirectDatabaseQuery.SchemaChange + 'DROP TABLE IF EXISTS %i', + $wpdb->prefix . \ProgressPlanner\Query::TABLE_NAME + ) +); From 84aaa2c6d3573a2287251e7272a732da6101dd2b Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 4 Apr 2024 14:43:35 +0300 Subject: [PATCH 310/490] Run phpstan checks and fix all reported issues --- includes/actions/class-content.php | 14 ++++++++----- includes/actions/class-maintenance.php | 6 +++--- includes/activities/class-content-helpers.php | 2 +- includes/activities/class-content.php | 4 ++-- includes/admin/class-dashboard-widget.php | 4 ++++ .../badges/badge/class-awesome-author.php | 2 ++ .../badges/badge/class-maintenance-maniac.php | 2 ++ .../badges/badge/class-notorious-novelist.php | 2 ++ .../badge/class-progress-professional.php | 2 ++ .../badge/class-super-site-specialist.php | 2 ++ .../badges/badge/class-wonderful-writer.php | 2 ++ includes/badges/class-badge.php | 6 ++++++ includes/class-activity.php | 10 ++++++++++ includes/class-badges.php | 6 ++---- includes/class-chart.php | 2 ++ includes/class-date.php | 4 +++- includes/class-query.php | 2 +- includes/class-rest-api.php | 2 ++ includes/goals/class-goal-recurring.php | 20 +++++++------------ includes/widgets/class-badge-content.php | 2 +- includes/widgets/class-badge-streak.php | 2 +- .../widgets/class-personal-record-content.php | 2 +- includes/widgets/class-plugins.php | 2 +- .../class-published-content-density.php | 8 ++++---- includes/widgets/class-published-content.php | 2 +- includes/widgets/class-published-words.php | 6 +++--- .../widgets/class-website-activity-score.php | 6 +++--- includes/widgets/class-widget.php | 4 ++-- phpstan.neon.dist | 2 ++ 29 files changed, 83 insertions(+), 47 deletions(-) diff --git a/includes/actions/class-content.php b/includes/actions/class-content.php index e8098da34..3a40bf0eb 100644 --- a/includes/actions/class-content.php +++ b/includes/actions/class-content.php @@ -40,6 +40,8 @@ public function __construct() { /** * Register hooks. + * + * @return void */ public function register_hooks() { // Add activity when a post is updated. @@ -62,8 +64,8 @@ public function register_hooks() { * * Runs on post_updated hook. * - * @param int $post_id The post ID. - * @param WP_Post $post The post object. + * @param int $post_id The post ID. + * @param \WP_Post $post The post object. * * @return void */ @@ -98,8 +100,8 @@ public function post_updated( $post_id, $post ) { * * Runs on wp_insert_post hook. * - * @param int $post_id The post ID. - * @param WP_Post $post The post object. + * @param int $post_id The post ID. + * @param \WP_Post $post The post object. * @return void */ public function insert_post( $post_id, $post ) { @@ -133,6 +135,8 @@ public function insert_post( $post_id, $post ) { * @param string $new_status The new status. * @param string $old_status The old status. * @param \WP_Post $post The post object. + * + * @return void */ public function transition_post_status( $new_status, $old_status, $post ) { // Bail if we should skip saving. @@ -277,7 +281,7 @@ private function add_post_activity( $post, $type ) { foreach ( $badge_ids as $badge_id ) { // If the badge is already complete, skip it. - if ( 100 === Settings::get( 'badges', $badge_id, 'progress', 0 ) ) { + if ( 100 === Settings::get( [ 'badges', $badge_id, 'progress' ], 0 ) ) { continue; } diff --git a/includes/actions/class-maintenance.php b/includes/actions/class-maintenance.php index 426a0f6f5..730f4880f 100644 --- a/includes/actions/class-maintenance.php +++ b/includes/actions/class-maintenance.php @@ -31,8 +31,8 @@ protected function register_hooks() { \add_action( 'upgrader_process_complete', [ $this, 'on_upgrade' ], 10, 2 ); // Deletions. - \add_action( 'delete_plugin', [ $this, 'on_delete_plugin' ], 10, 2 ); - \add_action( 'delete_theme', [ $this, 'on_delete_plugin' ], 10, 2 ); + \add_action( 'delete_plugin', [ $this, 'on_delete_plugin' ] ); + \add_action( 'delete_theme', [ $this, 'on_delete_plugin' ] ); // Installations. \add_action( 'upgrader_process_complete', [ $this, 'on_install' ], 10, 2 ); @@ -42,7 +42,7 @@ protected function register_hooks() { \add_action( 'deactivated_plugin', [ $this, 'on_deactivate_plugin' ], 10 ); // Theme switching. - \add_action( 'switch_theme', [ $this, 'on_switch_theme' ], 10, 2 ); + \add_action( 'switch_theme', [ $this, 'on_switch_theme' ] ); } /** diff --git a/includes/activities/class-content-helpers.php b/includes/activities/class-content-helpers.php index 8c6c8d729..b125831f6 100644 --- a/includes/activities/class-content-helpers.php +++ b/includes/activities/class-content-helpers.php @@ -76,7 +76,7 @@ public static function get_activity_from_post( $post ) { $activity->set_type( $type ); $activity->set_date( Date::get_datetime_from_mysql_date( $date ) ); $activity->set_data_id( $post->ID ); - $activity->set_user_id( $post->post_author ); + $activity->set_user_id( (int) $post->post_author ); return $activity; } } diff --git a/includes/activities/class-content.php b/includes/activities/class-content.php index ca5bfeb36..5b7eefee7 100644 --- a/includes/activities/class-content.php +++ b/includes/activities/class-content.php @@ -27,7 +27,7 @@ class Content extends Activity { /** * Get WP_Post from the activity. * - * @return \WP_Post + * @return \WP_Post|null */ public function get_post() { return \get_post( $this->data_id ); @@ -77,6 +77,6 @@ public function get_points( $date ) { ? round( $this->points[ $date_ymd ] ) // If the activity is new (less than 7 days old), award full points. : round( $this->points[ $date_ymd ] * max( 0, ( 1 - $days / 30 ) ) ); // Decay the points based on the age of the activity. - return $this->points[ $date_ymd ]; + return (int) $this->points[ $date_ymd ]; } } diff --git a/includes/admin/class-dashboard-widget.php b/includes/admin/class-dashboard-widget.php index ef3c1b382..1b936c10b 100644 --- a/includes/admin/class-dashboard-widget.php +++ b/includes/admin/class-dashboard-widget.php @@ -23,6 +23,8 @@ public function __construct() { /** * Add the dashboard widget. + * + * @return void */ public function add_dashboard_widget() { \wp_add_dashboard_widget( @@ -34,6 +36,8 @@ public function add_dashboard_widget() { /** * Render the dashboard widget. + * + * @return void */ public function render_dashboard_widget() { Page::enqueue_styles(); diff --git a/includes/badges/badge/class-awesome-author.php b/includes/badges/badge/class-awesome-author.php index 5f7d34f58..d27093a8a 100644 --- a/includes/badges/badge/class-awesome-author.php +++ b/includes/badges/badge/class-awesome-author.php @@ -51,6 +51,8 @@ public function get_icons_svg() { /** * Progress callback. + * + * @return array */ public function progress_callback() { $saved_progress = $this->get_saved(); diff --git a/includes/badges/badge/class-maintenance-maniac.php b/includes/badges/badge/class-maintenance-maniac.php index 54c627849..6489ad430 100644 --- a/includes/badges/badge/class-maintenance-maniac.php +++ b/includes/badges/badge/class-maintenance-maniac.php @@ -51,6 +51,8 @@ public function get_icons_svg() { /** * Progress callback. + * + * @return array */ public function progress_callback() { $saved_progress = $this->get_saved(); diff --git a/includes/badges/badge/class-notorious-novelist.php b/includes/badges/badge/class-notorious-novelist.php index 8982cbe8f..5721ad6f6 100644 --- a/includes/badges/badge/class-notorious-novelist.php +++ b/includes/badges/badge/class-notorious-novelist.php @@ -51,6 +51,8 @@ public function get_icons_svg() { /** * Progress callback. + * + * @return array */ public function progress_callback() { $saved_progress = $this->get_saved(); diff --git a/includes/badges/badge/class-progress-professional.php b/includes/badges/badge/class-progress-professional.php index 336c0921b..82c28e212 100644 --- a/includes/badges/badge/class-progress-professional.php +++ b/includes/badges/badge/class-progress-professional.php @@ -50,6 +50,8 @@ public function get_icons_svg() { /** * Progress callback. + * + * @return array */ public function progress_callback() { $saved_progress = $this->get_saved(); diff --git a/includes/badges/badge/class-super-site-specialist.php b/includes/badges/badge/class-super-site-specialist.php index eca1332c6..6ae93426f 100644 --- a/includes/badges/badge/class-super-site-specialist.php +++ b/includes/badges/badge/class-super-site-specialist.php @@ -50,6 +50,8 @@ public function get_icons_svg() { /** * Progress callback. + * + * @return array */ public function progress_callback() { $saved_progress = $this->get_saved(); diff --git a/includes/badges/badge/class-wonderful-writer.php b/includes/badges/badge/class-wonderful-writer.php index 7dee32620..5c012edf9 100644 --- a/includes/badges/badge/class-wonderful-writer.php +++ b/includes/badges/badge/class-wonderful-writer.php @@ -52,6 +52,8 @@ public function get_icons_svg() { /** * Progress callback. + * + * @return array */ public function progress_callback() { // Get the saved progress. diff --git a/includes/badges/class-badge.php b/includes/badges/class-badge.php index cbfe79061..90cc65b9d 100644 --- a/includes/badges/class-badge.php +++ b/includes/badges/class-badge.php @@ -31,6 +31,8 @@ public function __construct() { /** * Register the badge. + * + * @return void */ public function register_badge() { Badges::register_badge( @@ -59,6 +61,8 @@ abstract public function get_icons_svg(); /** * Progress callback. + * + * @return array */ abstract public function progress_callback(); @@ -75,6 +79,8 @@ protected function get_saved() { * Save the progress. * * @param array $progress The progress to save. + * + * @return void */ protected function save_progress( $progress ) { $progress['date'] = ( new \DateTime() )->format( 'Y-m-d H:i:s' ); diff --git a/includes/class-activity.php b/includes/class-activity.php index d0d04a82d..aaaaaa11e 100644 --- a/includes/class-activity.php +++ b/includes/class-activity.php @@ -89,6 +89,8 @@ public function get_id() { * Set the date. * * @param \DateTime $date The date of the activity. + * + * @return void */ public function set_date( \DateTime $date ) { $this->date = $date; @@ -107,6 +109,8 @@ public function get_date() { * Set the category. * * @param string $category The category of the activity. + * + * @return void */ public function set_category( string $category ) { $this->category = $category; @@ -125,6 +129,8 @@ public function get_category() { * Set the type. * * @param string $type The type of the activity. + * + * @return void */ public function set_type( string $type ) { $this->type = $type; @@ -143,6 +149,8 @@ public function get_type() { * Set the data ID. * * @param int $data_id The data ID. + * + * @return void */ public function set_data_id( int $data_id ) { $this->data_id = $data_id; @@ -161,6 +169,8 @@ public function get_data_id() { * Set the user ID. * * @param int $user_id The user ID. + * + * @return void */ public function set_user_id( int $user_id ) { $this->user_id = (int) $user_id; diff --git a/includes/class-badges.php b/includes/class-badges.php index de9c01aba..40a37f5b0 100644 --- a/includes/class-badges.php +++ b/includes/class-badges.php @@ -58,7 +58,7 @@ public static function get_badges() { * * @param string $badge_id The badge ID. * - * @return int + * @return array */ public static function get_badge_progress( $badge_id ) { $badge = self::get_badge( $badge_id ); @@ -111,9 +111,7 @@ public static function get_latest_completed_badge() { } // Compare dates. - if ( null === $latest_date || - \DateTime::createFromFormat( 'Y-m-d H:i:s', $settings[ $badge_id ]['date'] )->format( 'U' ) > \DateTime::createFromFormat( 'Y-m-d H:i:s', $latest_date )->format( 'U' ) - ) { + if ( \DateTime::createFromFormat( 'Y-m-d H:i:s', $settings[ $badge_id ]['date'] )->format( 'U' ) > \DateTime::createFromFormat( 'Y-m-d H:i:s', $latest_date )->format( 'U' ) ) { $latest_date = $settings[ $badge_id ]['date']; $latest_id = $badge_id; } diff --git a/includes/class-chart.php b/includes/class-chart.php index d74a12c88..0b481291a 100644 --- a/includes/class-chart.php +++ b/includes/class-chart.php @@ -35,6 +35,8 @@ class Chart { * @return void */ public function the_chart( $args = [] ) { + $activities = []; + /* * Set default values for the arguments. */ diff --git a/includes/class-date.php b/includes/class-date.php index a971597c0..59aa83887 100644 --- a/includes/class-date.php +++ b/includes/class-date.php @@ -87,7 +87,7 @@ public static function get_periods( $start, $end, $frequency ) { * @return \DateTime */ public static function get_datetime_from_mysql_date( $date ) { - return \DateTime::createFromFormat( 'U', (int) \mysql2date( 'U', $date ) ); + return \DateTime::createFromFormat( 'U', (string) \mysql2date( 'U', $date ) ); } /** @@ -95,6 +95,8 @@ public static function get_datetime_from_mysql_date( $date ) { * * @param \DateTime $date1 The first date. * @param \DateTime $date2 The second date. + * + * @return int */ public static function get_days_between_dates( $date1, $date2 ) { return (int) $date1->diff( $date2 )->format( '%R%a' ); diff --git a/includes/class-query.php b/includes/class-query.php index 8f5627ce2..0c319a057 100644 --- a/includes/class-query.php +++ b/includes/class-query.php @@ -99,7 +99,7 @@ private function create_activities_table() { * @param array $args The arguments for the query. * @param string $return_type The type of the return value. Can be "RAW" or "ACTIVITIES". * - * @return \ProgressPlanner\Activity[] The activities. + * @return array The activities. */ public function query_activities( $args, $return_type = 'ACTIVITIES' ) { global $wpdb; diff --git a/includes/class-rest-api.php b/includes/class-rest-api.php index 78dbdff7f..b3cdb7ce3 100644 --- a/includes/class-rest-api.php +++ b/includes/class-rest-api.php @@ -114,6 +114,8 @@ public function get_stats( \WP_REST_Request $request ) { * Validate the token. * * @param string $token The token. + * + * @return bool */ public function validate_token( $token ) { $token = str_replace( 'token/', '', $token ); diff --git a/includes/goals/class-goal-recurring.php b/includes/goals/class-goal-recurring.php index 5e69da892..ee372de12 100644 --- a/includes/goals/class-goal-recurring.php +++ b/includes/goals/class-goal-recurring.php @@ -8,6 +8,7 @@ namespace ProgressPlanner\Goals; use ProgressPlanner\Date; +use ProgressPlanner\Goals\Goal; /** * A recurring goal. @@ -31,14 +32,14 @@ class Goal_Recurring { /** * The start date. * - * @var int|string + * @var \DateTime */ private $start; /** * The end date. * - * @var int|string + * @var \DateTime */ private $end; @@ -69,6 +70,8 @@ class Goal_Recurring { * @param string $id The recurring goal ID. * @param array $goal_args The goal arguments. * @param array $args The recurring goal arguments. + * + * @return Goal_Recurring */ public static function get_instance( $id, $goal_args, $args ) { if ( ! isset( self::$instances[ $id ] ) ) { @@ -103,7 +106,7 @@ private function __construct( $goal, $args ) { /** * Get the goal title. * - * @return string + * @return Goal */ public function get_goal() { return $this->goal; @@ -146,18 +149,9 @@ public function get_occurences() { /** * Get the streak for weekly posts. * - * @return int The number of weeks for this streak. + * @return array */ public function get_streak() { - // Bail early if there is no goal. - if ( ! $this->get_goal() ) { - return [ - 'number' => 0, - 'title' => '', - 'description' => '', - ]; - } - // Reverse the order of the occurences. $occurences = $this->get_occurences(); diff --git a/includes/widgets/class-badge-content.php b/includes/widgets/class-badge-content.php index dd1fc9c1c..db76bf332 100644 --- a/includes/widgets/class-badge-content.php +++ b/includes/widgets/class-badge-content.php @@ -38,7 +38,7 @@ class="prpl-badge"
- render_big_counter( $record['max_streak'], __( 'personal record', 'progress-planner' ) ); ?> + render_big_counter( (int) $record['max_streak'], __( 'personal record', 'progress-planner' ) ); ?>

diff --git a/includes/widgets/class-plugins.php b/includes/widgets/class-plugins.php index 502ec3cf9..1c2b0211d 100644 --- a/includes/widgets/class-plugins.php +++ b/includes/widgets/class-plugins.php @@ -35,7 +35,7 @@ protected function the_content() { ?>

- render_big_counter( $plugins_count, __( 'plugins', 'progress-planner' ) ); ?> + render_big_counter( (int) $plugins_count, __( 'plugins', 'progress-planner' ) ); ?>

diff --git a/includes/widgets/class-published-content-density.php b/includes/widgets/class-published-content-density.php index a4b986e53..c657b60ce 100644 --- a/includes/widgets/class-published-content-density.php +++ b/includes/widgets/class-published-content-density.php @@ -32,7 +32,7 @@ protected function the_content() { ?>
- render_big_counter( $this->get_weekly_activities_density(), __( 'content density', 'progress-planner' ) ); ?> + render_big_counter( (int) $this->get_weekly_activities_density(), __( 'content density', 'progress-planner' ) ); ?>

count_words( $activities ); $count = count( $activities ); - return round( $words / max( 1, $count ) ); + return (int) round( $words / max( 1, $count ) ); } /** diff --git a/includes/widgets/class-published-content.php b/includes/widgets/class-published-content.php index 2a1367ba2..3b14e5167 100644 --- a/includes/widgets/class-published-content.php +++ b/includes/widgets/class-published-content.php @@ -34,7 +34,7 @@ protected function the_content() { ?>

- render_big_counter( array_sum( $stats['weekly'] ), __( 'content published', 'progress-planner' ) ); ?> + render_big_counter( (int) array_sum( $stats['weekly'] ), __( 'content published', 'progress-planner' ) ); ?>

diff --git a/includes/widgets/class-published-words.php b/includes/widgets/class-published-words.php index 544d3cca3..9d24410fa 100644 --- a/includes/widgets/class-published-words.php +++ b/includes/widgets/class-published-words.php @@ -31,7 +31,7 @@ protected function the_content() { ?>

- render_big_counter( $this->get_weekly_words(), __( 'words written', 'progress-planner' ) ); ?> + render_big_counter( (int) $this->get_weekly_words(), __( 'words written', 'progress-planner' ) ); ?>

get_weekly_words() ) : ?> @@ -91,14 +91,14 @@ public function get_chart_args() { /** * Callback to count the words in the activities. * - * @param \ProgressPlanner\Activity[] $activities The activities array. + * @param \ProgressPlanner\Activities\Content[] $activities The activities array. * * @return int */ public function count_words( $activities ) { $words = 0; foreach ( $activities as $activity ) { - if ( ! $activity->get_post() ) { + if ( null === $activity->get_post() ) { continue; } $words += Content_Helpers::get_word_count( diff --git a/includes/widgets/class-website-activity-score.php b/includes/widgets/class-website-activity-score.php index bac5cc83e..8650bd9cd 100644 --- a/includes/widgets/class-website-activity-score.php +++ b/includes/widgets/class-website-activity-score.php @@ -53,14 +53,14 @@ public static function print_score_gauge() {

- +
@@ -113,7 +113,7 @@ protected static function get_score() { // Reduce points for pending updates. $score -= min( min( $score / 2, 25 ), $pending_updates * 5 ); - return floor( $score ); + return (int) floor( $score ); } /** diff --git a/includes/widgets/class-widget.php b/includes/widgets/class-widget.php index 342be6185..48a5039a7 100644 --- a/includes/widgets/class-widget.php +++ b/includes/widgets/class-widget.php @@ -66,12 +66,12 @@ protected function render() { /** * Render a big counter. * - * @param string $number The number to display. + * @param int $number The number to display. * @param string $text The text to display. * * @return void */ - protected function render_big_counter( $number, $text ) { + protected function render_big_counter( int $number, $text ) { ?>
diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 8f93d17fa..220c1d453 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -4,6 +4,8 @@ parameters: - . excludePaths: - vendor + - tests + checkGenericClassInNonGenericObjectType: false ignoreErrors: - '#Constant PROGRESS_PLANNER_URL not found.#' - '#Property [a-zA-Z0-9\\_]+::\$[a-zA-Z0-9\\_]+ type has no value type specified in iterable type array.#' From 90ee9fbbbed18ac66d854590e51dd0d7e480b37a Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 4 Apr 2024 14:51:57 +0300 Subject: [PATCH 311/490] Try adding a workflow for phpstan --- .github/workflows/phpstan.yml | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/phpstan.yml diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml new file mode 100644 index 000000000..8f9583bad --- /dev/null +++ b/.github/workflows/phpstan.yml @@ -0,0 +1,36 @@ +name: Run PHPStan + +on: + # Run on pushes to select branches and on all pull requests. + push: + branches: + - main + - develop + - 'release/[0-9]+.[0-9]+*' + - 'hotfix/[0-9]+.[0-9]+*' + pull_request: + # Allow manually triggering the workflow. + workflow_dispatch: + +jobs: + phpstan: + name: Static Analysis + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 'latest' + coverage: none + tools: composer, cs2pr + + - name: Install PHP dependencies + uses: ramsey/composer-install@v2 + with: + composer-options: '--prefer-dist --no-scripts' + + - name: PHPStan + run: composer phpstan From 4478031f456a2434c5e03cac98d8ac6e4f8f5623 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 4 Apr 2024 15:20:11 +0300 Subject: [PATCH 312/490] commit the composer.lock file --- .gitignore | 3 - composer.lock | 3056 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 3056 insertions(+), 3 deletions(-) create mode 100644 composer.lock diff --git a/.gitignore b/.gitignore index c7af010f4..b5f3f2087 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,4 @@ vendor/ - -composer.lock ._* - .phpunit.result.cache diff --git a/composer.lock b/composer.lock new file mode 100644 index 000000000..ca5a34248 --- /dev/null +++ b/composer.lock @@ -0,0 +1,3056 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "b2c54a911d93966cead952a962209a34", + "packages": [], + "packages-dev": [ + { + "name": "antecedent/patchwork", + "version": "2.1.28", + "source": { + "type": "git", + "url": "https://github.com/antecedent/patchwork.git", + "reference": "6b30aff81ebadf0f2feb9268d3e08385cebcc08d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/antecedent/patchwork/zipball/6b30aff81ebadf0f2feb9268d3e08385cebcc08d", + "reference": "6b30aff81ebadf0f2feb9268d3e08385cebcc08d", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": ">=4" + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ignas Rudaitis", + "email": "ignas.rudaitis@gmail.com" + } + ], + "description": "Method redefinition (monkey-patching) functionality for PHP.", + "homepage": "https://antecedent.github.io/patchwork/", + "keywords": [ + "aop", + "aspect", + "interception", + "monkeypatching", + "redefinition", + "runkit", + "testing" + ], + "support": { + "issues": "https://github.com/antecedent/patchwork/issues", + "source": "https://github.com/antecedent/patchwork/tree/2.1.28" + }, + "time": "2024-02-06T09:26:11+00:00" + }, + { + "name": "brain/monkey", + "version": "2.6.1", + "source": { + "type": "git", + "url": "https://github.com/Brain-WP/BrainMonkey.git", + "reference": "a31c84515bb0d49be9310f52ef1733980ea8ffbb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Brain-WP/BrainMonkey/zipball/a31c84515bb0d49be9310f52ef1733980ea8ffbb", + "reference": "a31c84515bb0d49be9310f52ef1733980ea8ffbb", + "shasum": "" + }, + "require": { + "antecedent/patchwork": "^2.1.17", + "mockery/mockery": "^1.3.5 || ^1.4.4", + "php": ">=5.6.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7.1", + "phpcompatibility/php-compatibility": "^9.3.0", + "phpunit/phpunit": "^5.7.26 || ^6.0 || ^7.0 || >=8.0 <8.5.12 || ^8.5.14 || ^9.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-version/1": "1.x-dev", + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "files": [ + "inc/api.php" + ], + "psr-4": { + "Brain\\Monkey\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Giuseppe Mazzapica", + "email": "giuseppe.mazzapica@gmail.com", + "homepage": "https://gmazzap.me", + "role": "Developer" + } + ], + "description": "Mocking utility for PHP functions and WordPress plugin API", + "keywords": [ + "Monkey Patching", + "interception", + "mock", + "mock functions", + "mockery", + "patchwork", + "redefinition", + "runkit", + "test", + "testing" + ], + "support": { + "issues": "https://github.com/Brain-WP/BrainMonkey/issues", + "source": "https://github.com/Brain-WP/BrainMonkey" + }, + "time": "2021-11-11T15:53:55+00:00" + }, + { + "name": "dealerdirect/phpcodesniffer-composer-installer", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/composer-installer.git", + "reference": "4be43904336affa5c2f70744a348312336afd0da" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/composer-installer/zipball/4be43904336affa5c2f70744a348312336afd0da", + "reference": "4be43904336affa5c2f70744a348312336afd0da", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0 || ^2.0", + "php": ">=5.4", + "squizlabs/php_codesniffer": "^2.0 || ^3.1.0 || ^4.0" + }, + "require-dev": { + "composer/composer": "*", + "ext-json": "*", + "ext-zip": "*", + "php-parallel-lint/php-parallel-lint": "^1.3.1", + "phpcompatibility/php-compatibility": "^9.0", + "yoast/phpunit-polyfills": "^1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + }, + "autoload": { + "psr-4": { + "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Franck Nijhof", + "email": "franck.nijhof@dealerdirect.com", + "homepage": "http://www.frenck.nl", + "role": "Developer / IT Manager" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/composer-installer/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer Standards Composer Installer Plugin", + "homepage": "http://www.dealerdirect.com", + "keywords": [ + "PHPCodeSniffer", + "PHP_CodeSniffer", + "code quality", + "codesniffer", + "composer", + "installer", + "phpcbf", + "phpcs", + "plugin", + "qa", + "quality", + "standard", + "standards", + "style guide", + "stylecheck", + "tests" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/composer-installer/issues", + "source": "https://github.com/PHPCSStandards/composer-installer" + }, + "time": "2023-01-05T11:28:13+00:00" + }, + { + "name": "doctrine/instantiator", + "version": "1.5.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "0a0fa9780f5d4e507415a065172d26a98d02047b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/0a0fa9780f5d4e507415a065172d26a98d02047b", + "reference": "0a0fa9780f5d4e507415a065172d26a98d02047b", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "require-dev": { + "doctrine/coding-standard": "^9 || ^11", + "ext-pdo": "*", + "ext-phar": "*", + "phpbench/phpbench": "^0.16 || ^1", + "phpstan/phpstan": "^1.4", + "phpstan/phpstan-phpunit": "^1", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", + "vimeo/psalm": "^4.30 || ^5.4" + }, + "type": "library", + "autoload": { + "psr-4": { + "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "https://ocramius.github.io/" + } + ], + "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", + "homepage": "https://www.doctrine-project.org/projects/instantiator.html", + "keywords": [ + "constructor", + "instantiate" + ], + "support": { + "issues": "https://github.com/doctrine/instantiator/issues", + "source": "https://github.com/doctrine/instantiator/tree/1.5.0" + }, + "funding": [ + { + "url": "https://www.doctrine-project.org/sponsorship.html", + "type": "custom" + }, + { + "url": "https://www.patreon.com/phpdoctrine", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/doctrine%2Finstantiator", + "type": "tidelift" + } + ], + "time": "2022-12-30T00:15:36+00:00" + }, + { + "name": "hamcrest/hamcrest-php", + "version": "v2.0.1", + "source": { + "type": "git", + "url": "https://github.com/hamcrest/hamcrest-php.git", + "reference": "8c3d0a3f6af734494ad8f6fbbee0ba92422859f3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/hamcrest/hamcrest-php/zipball/8c3d0a3f6af734494ad8f6fbbee0ba92422859f3", + "reference": "8c3d0a3f6af734494ad8f6fbbee0ba92422859f3", + "shasum": "" + }, + "require": { + "php": "^5.3|^7.0|^8.0" + }, + "replace": { + "cordoval/hamcrest-php": "*", + "davedevelopment/hamcrest-php": "*", + "kodova/hamcrest-php": "*" + }, + "require-dev": { + "phpunit/php-file-iterator": "^1.4 || ^2.0", + "phpunit/phpunit": "^4.8.36 || ^5.7 || ^6.5 || ^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "autoload": { + "classmap": [ + "hamcrest" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "This is the PHP port of Hamcrest Matchers", + "keywords": [ + "test" + ], + "support": { + "issues": "https://github.com/hamcrest/hamcrest-php/issues", + "source": "https://github.com/hamcrest/hamcrest-php/tree/v2.0.1" + }, + "time": "2020-07-09T08:09:16+00:00" + }, + { + "name": "mockery/mockery", + "version": "1.6.11", + "source": { + "type": "git", + "url": "https://github.com/mockery/mockery.git", + "reference": "81a161d0b135df89951abd52296adf97deb0723d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/mockery/mockery/zipball/81a161d0b135df89951abd52296adf97deb0723d", + "reference": "81a161d0b135df89951abd52296adf97deb0723d", + "shasum": "" + }, + "require": { + "hamcrest/hamcrest-php": "^2.0.1", + "lib-pcre": ">=7.0", + "php": ">=7.3" + }, + "conflict": { + "phpunit/phpunit": "<8.0" + }, + "require-dev": { + "phpunit/phpunit": "^8.5 || ^9.6.17", + "symplify/easy-coding-standard": "^12.1.14" + }, + "type": "library", + "autoload": { + "files": [ + "library/helpers.php", + "library/Mockery.php" + ], + "psr-4": { + "Mockery\\": "library/Mockery" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Pádraic Brady", + "email": "padraic.brady@gmail.com", + "homepage": "https://github.com/padraic", + "role": "Author" + }, + { + "name": "Dave Marshall", + "email": "dave.marshall@atstsolutions.co.uk", + "homepage": "https://davedevelopment.co.uk", + "role": "Developer" + }, + { + "name": "Nathanael Esayeas", + "email": "nathanael.esayeas@protonmail.com", + "homepage": "https://github.com/ghostwriter", + "role": "Lead Developer" + } + ], + "description": "Mockery is a simple yet flexible PHP mock object framework", + "homepage": "https://github.com/mockery/mockery", + "keywords": [ + "BDD", + "TDD", + "library", + "mock", + "mock objects", + "mockery", + "stub", + "test", + "test double", + "testing" + ], + "support": { + "docs": "https://docs.mockery.io/", + "issues": "https://github.com/mockery/mockery/issues", + "rss": "https://github.com/mockery/mockery/releases.atom", + "security": "https://github.com/mockery/mockery/security/advisories", + "source": "https://github.com/mockery/mockery" + }, + "time": "2024-03-21T18:34:15+00:00" + }, + { + "name": "myclabs/deep-copy", + "version": "1.11.1", + "source": { + "type": "git", + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/7284c22080590fb39f2ffa3e9057f10a4ddd0e0c", + "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "conflict": { + "doctrine/collections": "<1.6.8", + "doctrine/common": "<2.13.3 || >=3,<3.2.2" + }, + "require-dev": { + "doctrine/collections": "^1.6.8", + "doctrine/common": "^2.13.3 || ^3.2.2", + "phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13" + }, + "type": "library", + "autoload": { + "files": [ + "src/DeepCopy/deep_copy.php" + ], + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Create deep copies (clones) of your objects", + "keywords": [ + "clone", + "copy", + "duplicate", + "object", + "object graph" + ], + "support": { + "issues": "https://github.com/myclabs/DeepCopy/issues", + "source": "https://github.com/myclabs/DeepCopy/tree/1.11.1" + }, + "funding": [ + { + "url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy", + "type": "tidelift" + } + ], + "time": "2023-03-08T13:26:56+00:00" + }, + { + "name": "nikic/php-parser", + "version": "v5.0.2", + "source": { + "type": "git", + "url": "https://github.com/nikic/PHP-Parser.git", + "reference": "139676794dc1e9231bf7bcd123cfc0c99182cb13" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/139676794dc1e9231bf7bcd123cfc0c99182cb13", + "reference": "139676794dc1e9231bf7bcd123cfc0c99182cb13", + "shasum": "" + }, + "require": { + "ext-ctype": "*", + "ext-json": "*", + "ext-tokenizer": "*", + "php": ">=7.4" + }, + "require-dev": { + "ircmaxell/php-yacc": "^0.0.7", + "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0" + }, + "bin": [ + "bin/php-parse" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "psr-4": { + "PhpParser\\": "lib/PhpParser" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Nikita Popov" + } + ], + "description": "A PHP parser written in PHP", + "keywords": [ + "parser", + "php" + ], + "support": { + "issues": "https://github.com/nikic/PHP-Parser/issues", + "source": "https://github.com/nikic/PHP-Parser/tree/v5.0.2" + }, + "time": "2024-03-05T20:51:40+00:00" + }, + { + "name": "phar-io/manifest", + "version": "2.0.4", + "source": { + "type": "git", + "url": "https://github.com/phar-io/manifest.git", + "reference": "54750ef60c58e43759730615a392c31c80e23176" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/54750ef60c58e43759730615a392c31c80e23176", + "reference": "54750ef60c58e43759730615a392c31c80e23176", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-libxml": "*", + "ext-phar": "*", + "ext-xmlwriter": "*", + "phar-io/version": "^3.0.1", + "php": "^7.2 || ^8.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", + "support": { + "issues": "https://github.com/phar-io/manifest/issues", + "source": "https://github.com/phar-io/manifest/tree/2.0.4" + }, + "funding": [ + { + "url": "https://github.com/theseer", + "type": "github" + } + ], + "time": "2024-03-03T12:33:53+00:00" + }, + { + "name": "phar-io/version", + "version": "3.2.1", + "source": { + "type": "git", + "url": "https://github.com/phar-io/version.git", + "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/version/zipball/4f7fd7836c6f332bb2933569e566a0d6c4cbed74", + "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Library for handling version information and constraints", + "support": { + "issues": "https://github.com/phar-io/version/issues", + "source": "https://github.com/phar-io/version/tree/3.2.1" + }, + "time": "2022-02-21T01:04:05+00:00" + }, + { + "name": "php-parallel-lint/php-parallel-lint", + "version": "v1.4.0", + "source": { + "type": "git", + "url": "https://github.com/php-parallel-lint/PHP-Parallel-Lint.git", + "reference": "6db563514f27e19595a19f45a4bf757b6401194e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-parallel-lint/PHP-Parallel-Lint/zipball/6db563514f27e19595a19f45a4bf757b6401194e", + "reference": "6db563514f27e19595a19f45a4bf757b6401194e", + "shasum": "" + }, + "require": { + "ext-json": "*", + "php": ">=5.3.0" + }, + "replace": { + "grogy/php-parallel-lint": "*", + "jakub-onderka/php-parallel-lint": "*" + }, + "require-dev": { + "nette/tester": "^1.3 || ^2.0", + "php-parallel-lint/php-console-highlighter": "0.* || ^1.0", + "squizlabs/php_codesniffer": "^3.6" + }, + "suggest": { + "php-parallel-lint/php-console-highlighter": "Highlight syntax in code snippet" + }, + "bin": [ + "parallel-lint" + ], + "type": "library", + "autoload": { + "classmap": [ + "./src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Jakub Onderka", + "email": "ahoj@jakubonderka.cz" + } + ], + "description": "This tool checks the syntax of PHP files about 20x faster than serial check.", + "homepage": "https://github.com/php-parallel-lint/PHP-Parallel-Lint", + "keywords": [ + "lint", + "static analysis" + ], + "support": { + "issues": "https://github.com/php-parallel-lint/PHP-Parallel-Lint/issues", + "source": "https://github.com/php-parallel-lint/PHP-Parallel-Lint/tree/v1.4.0" + }, + "time": "2024-03-27T12:14:49+00:00" + }, + { + "name": "php-stubs/wordpress-stubs", + "version": "v6.4.3", + "source": { + "type": "git", + "url": "https://github.com/php-stubs/wordpress-stubs.git", + "reference": "6105bdab2f26c0204fe90ecc53d5684754550e8f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-stubs/wordpress-stubs/zipball/6105bdab2f26c0204fe90ecc53d5684754550e8f", + "reference": "6105bdab2f26c0204fe90ecc53d5684754550e8f", + "shasum": "" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^1.0", + "nikic/php-parser": "^4.13", + "php": "^7.4 || ~8.0.0", + "php-stubs/generator": "^0.8.3", + "phpdocumentor/reflection-docblock": "^5.3", + "phpstan/phpstan": "^1.10.49", + "phpunit/phpunit": "^9.5", + "szepeviktor/phpcs-psr-12-neutron-hybrid-ruleset": "^0.11" + }, + "suggest": { + "paragonie/sodium_compat": "Pure PHP implementation of libsodium", + "symfony/polyfill-php80": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", + "szepeviktor/phpstan-wordpress": "WordPress extensions for PHPStan" + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "WordPress function and class declaration stubs for static analysis.", + "homepage": "https://github.com/php-stubs/wordpress-stubs", + "keywords": [ + "PHPStan", + "static analysis", + "wordpress" + ], + "support": { + "issues": "https://github.com/php-stubs/wordpress-stubs/issues", + "source": "https://github.com/php-stubs/wordpress-stubs/tree/v6.4.3" + }, + "time": "2024-02-11T18:56:19+00:00" + }, + { + "name": "phpcompatibility/php-compatibility", + "version": "9.3.5", + "source": { + "type": "git", + "url": "https://github.com/PHPCompatibility/PHPCompatibility.git", + "reference": "9fb324479acf6f39452e0655d2429cc0d3914243" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibility/zipball/9fb324479acf6f39452e0655d2429cc0d3914243", + "reference": "9fb324479acf6f39452e0655d2429cc0d3914243", + "shasum": "" + }, + "require": { + "php": ">=5.3", + "squizlabs/php_codesniffer": "^2.3 || ^3.0.2" + }, + "conflict": { + "squizlabs/php_codesniffer": "2.6.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.5 || ^5.0 || ^6.0 || ^7.0" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.5 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically.", + "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Wim Godden", + "homepage": "https://github.com/wimg", + "role": "lead" + }, + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCompatibility/PHPCompatibility/graphs/contributors" + } + ], + "description": "A set of sniffs for PHP_CodeSniffer that checks for PHP cross-version compatibility.", + "homepage": "http://techblog.wimgodden.be/tag/codesniffer/", + "keywords": [ + "compatibility", + "phpcs", + "standards" + ], + "support": { + "issues": "https://github.com/PHPCompatibility/PHPCompatibility/issues", + "source": "https://github.com/PHPCompatibility/PHPCompatibility" + }, + "time": "2019-12-27T09:44:58+00:00" + }, + { + "name": "phpcompatibility/phpcompatibility-paragonie", + "version": "1.3.2", + "source": { + "type": "git", + "url": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie.git", + "reference": "bba5a9dfec7fcfbd679cfaf611d86b4d3759da26" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityParagonie/zipball/bba5a9dfec7fcfbd679cfaf611d86b4d3759da26", + "reference": "bba5a9dfec7fcfbd679cfaf611d86b4d3759da26", + "shasum": "" + }, + "require": { + "phpcompatibility/php-compatibility": "^9.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7", + "paragonie/random_compat": "dev-master", + "paragonie/sodium_compat": "dev-master" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", + "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Wim Godden", + "role": "lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "lead" + } + ], + "description": "A set of rulesets for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by the Paragonie polyfill libraries.", + "homepage": "http://phpcompatibility.com/", + "keywords": [ + "compatibility", + "paragonie", + "phpcs", + "polyfill", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie/issues", + "source": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie" + }, + "time": "2022-10-25T01:46:02+00:00" + }, + { + "name": "phpcompatibility/phpcompatibility-wp", + "version": "2.1.4", + "source": { + "type": "git", + "url": "https://github.com/PHPCompatibility/PHPCompatibilityWP.git", + "reference": "b6c1e3ee1c35de6c41a511d5eb9bd03e447480a5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityWP/zipball/b6c1e3ee1c35de6c41a511d5eb9bd03e447480a5", + "reference": "b6c1e3ee1c35de6c41a511d5eb9bd03e447480a5", + "shasum": "" + }, + "require": { + "phpcompatibility/php-compatibility": "^9.0", + "phpcompatibility/phpcompatibility-paragonie": "^1.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", + "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Wim Godden", + "role": "lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "lead" + } + ], + "description": "A ruleset for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by WordPress.", + "homepage": "http://phpcompatibility.com/", + "keywords": [ + "compatibility", + "phpcs", + "standards", + "static analysis", + "wordpress" + ], + "support": { + "issues": "https://github.com/PHPCompatibility/PHPCompatibilityWP/issues", + "source": "https://github.com/PHPCompatibility/PHPCompatibilityWP" + }, + "time": "2022-10-24T09:00:36+00:00" + }, + { + "name": "phpcsstandards/phpcsextra", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHPCSExtra.git", + "reference": "11d387c6642b6e4acaf0bd9bf5203b8cca1ec489" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSExtra/zipball/11d387c6642b6e4acaf0bd9bf5203b8cca1ec489", + "reference": "11d387c6642b6e4acaf0bd9bf5203b8cca1ec489", + "shasum": "" + }, + "require": { + "php": ">=5.4", + "phpcsstandards/phpcsutils": "^1.0.9", + "squizlabs/php_codesniffer": "^3.8.0" + }, + "require-dev": { + "php-parallel-lint/php-console-highlighter": "^1.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "phpcsstandards/phpcsdevcs": "^1.1.6", + "phpcsstandards/phpcsdevtools": "^1.2.1", + "phpunit/phpunit": "^4.5 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-stable": "1.x-dev", + "dev-develop": "1.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHPCSExtra/graphs/contributors" + } + ], + "description": "A collection of sniffs and standards for use with PHP_CodeSniffer.", + "keywords": [ + "PHP_CodeSniffer", + "phpcbf", + "phpcodesniffer-standard", + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/PHPCSExtra/issues", + "security": "https://github.com/PHPCSStandards/PHPCSExtra/security/policy", + "source": "https://github.com/PHPCSStandards/PHPCSExtra" + }, + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + } + ], + "time": "2023-12-08T16:49:07+00:00" + }, + { + "name": "phpcsstandards/phpcsutils", + "version": "1.0.10", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHPCSUtils.git", + "reference": "51609a5b89f928e0c463d6df80eb38eff1eaf544" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSUtils/zipball/51609a5b89f928e0c463d6df80eb38eff1eaf544", + "reference": "51609a5b89f928e0c463d6df80eb38eff1eaf544", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7 || ^1.0", + "php": ">=5.4", + "squizlabs/php_codesniffer": "^3.9.0 || 4.0.x-dev@dev" + }, + "require-dev": { + "ext-filter": "*", + "php-parallel-lint/php-console-highlighter": "^1.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "phpcsstandards/phpcsdevcs": "^1.1.6", + "yoast/phpunit-polyfills": "^1.1.0 || ^2.0.0" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-stable": "1.x-dev", + "dev-develop": "1.x-dev" + } + }, + "autoload": { + "classmap": [ + "PHPCSUtils/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHPCSUtils/graphs/contributors" + } + ], + "description": "A suite of utility functions for use with PHP_CodeSniffer", + "homepage": "https://phpcsutils.com/", + "keywords": [ + "PHP_CodeSniffer", + "phpcbf", + "phpcodesniffer-standard", + "phpcs", + "phpcs3", + "standards", + "static analysis", + "tokens", + "utility" + ], + "support": { + "docs": "https://phpcsutils.com/", + "issues": "https://github.com/PHPCSStandards/PHPCSUtils/issues", + "security": "https://github.com/PHPCSStandards/PHPCSUtils/security/policy", + "source": "https://github.com/PHPCSStandards/PHPCSUtils" + }, + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + } + ], + "time": "2024-03-17T23:44:50+00:00" + }, + { + "name": "phpstan/extension-installer", + "version": "1.3.1", + "source": { + "type": "git", + "url": "https://github.com/phpstan/extension-installer.git", + "reference": "f45734bfb9984c6c56c4486b71230355f066a58a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/extension-installer/zipball/f45734bfb9984c6c56c4486b71230355f066a58a", + "reference": "f45734bfb9984c6c56c4486b71230355f066a58a", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^2.0", + "php": "^7.2 || ^8.0", + "phpstan/phpstan": "^1.9.0" + }, + "require-dev": { + "composer/composer": "^2.0", + "php-parallel-lint/php-parallel-lint": "^1.2.0", + "phpstan/phpstan-strict-rules": "^0.11 || ^0.12 || ^1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "PHPStan\\ExtensionInstaller\\Plugin" + }, + "autoload": { + "psr-4": { + "PHPStan\\ExtensionInstaller\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Composer plugin for automatic installation of PHPStan extensions", + "support": { + "issues": "https://github.com/phpstan/extension-installer/issues", + "source": "https://github.com/phpstan/extension-installer/tree/1.3.1" + }, + "time": "2023-05-24T08:59:17+00:00" + }, + { + "name": "phpstan/phpstan", + "version": "1.10.66", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "94779c987e4ebd620025d9e5fdd23323903950bd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/94779c987e4ebd620025d9e5fdd23323903950bd", + "reference": "94779c987e4ebd620025d9e5fdd23323903950bd", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", + "issues": "https://github.com/phpstan/phpstan/issues", + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", + "type": "tidelift" + } + ], + "time": "2024-03-28T16:17:31+00:00" + }, + { + "name": "phpunit/php-code-coverage", + "version": "9.2.31", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "48c34b5d8d983006bd2adc2d0de92963b9155965" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/48c34b5d8d983006bd2adc2d0de92963b9155965", + "reference": "48c34b5d8d983006bd2adc2d0de92963b9155965", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-libxml": "*", + "ext-xmlwriter": "*", + "nikic/php-parser": "^4.18 || ^5.0", + "php": ">=7.3", + "phpunit/php-file-iterator": "^3.0.3", + "phpunit/php-text-template": "^2.0.2", + "sebastian/code-unit-reverse-lookup": "^2.0.2", + "sebastian/complexity": "^2.0", + "sebastian/environment": "^5.1.2", + "sebastian/lines-of-code": "^1.0.3", + "sebastian/version": "^3.0.1", + "theseer/tokenizer": "^1.2.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "suggest": { + "ext-pcov": "PHP extension that provides line coverage", + "ext-xdebug": "PHP extension that provides line coverage as well as branch and path coverage" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "9.2-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", + "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.31" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-03-02T06:37:42+00:00" + }, + { + "name": "phpunit/php-file-iterator", + "version": "3.0.6", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf", + "reference": "cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", + "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/3.0.6" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2021-12-02T12:48:52+00:00" + }, + { + "name": "phpunit/php-invoker", + "version": "3.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-invoker.git", + "reference": "5a10147d0aaf65b58940a0b72f71c9ac0423cc67" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/5a10147d0aaf65b58940a0b72f71c9ac0423cc67", + "reference": "5a10147d0aaf65b58940a0b72f71c9ac0423cc67", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "ext-pcntl": "*", + "phpunit/phpunit": "^9.3" + }, + "suggest": { + "ext-pcntl": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Invoke callables with a timeout", + "homepage": "https://github.com/sebastianbergmann/php-invoker/", + "keywords": [ + "process" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-invoker/issues", + "source": "https://github.com/sebastianbergmann/php-invoker/tree/3.1.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-09-28T05:58:55+00:00" + }, + { + "name": "phpunit/php-text-template", + "version": "2.0.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "5da5f67fc95621df9ff4c4e5a84d6a8a2acf7c28" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/5da5f67fc95621df9ff4c4e5a84d6a8a2acf7c28", + "reference": "5da5f67fc95621df9ff4c4e5a84d6a8a2acf7c28", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-text-template/issues", + "source": "https://github.com/sebastianbergmann/php-text-template/tree/2.0.4" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-10-26T05:33:50+00:00" + }, + { + "name": "phpunit/php-timer", + "version": "5.0.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "5a63ce20ed1b5bf577850e2c4e87f4aa902afbd2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/5a63ce20ed1b5bf577850e2c4e87f4aa902afbd2", + "reference": "5a63ce20ed1b5bf577850e2c4e87f4aa902afbd2", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-timer/issues", + "source": "https://github.com/sebastianbergmann/php-timer/tree/5.0.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-10-26T13:16:10+00:00" + }, + { + "name": "phpunit/phpunit", + "version": "9.6.18", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "32c2c2d6580b1d8ab3c10b1e9e4dc263cc69bb04" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/32c2c2d6580b1d8ab3c10b1e9e4dc263cc69bb04", + "reference": "32c2c2d6580b1d8ab3c10b1e9e4dc263cc69bb04", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.3.1 || ^2", + "ext-dom": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-xml": "*", + "ext-xmlwriter": "*", + "myclabs/deep-copy": "^1.10.1", + "phar-io/manifest": "^2.0.3", + "phar-io/version": "^3.0.2", + "php": ">=7.3", + "phpunit/php-code-coverage": "^9.2.28", + "phpunit/php-file-iterator": "^3.0.5", + "phpunit/php-invoker": "^3.1.1", + "phpunit/php-text-template": "^2.0.3", + "phpunit/php-timer": "^5.0.2", + "sebastian/cli-parser": "^1.0.1", + "sebastian/code-unit": "^1.0.6", + "sebastian/comparator": "^4.0.8", + "sebastian/diff": "^4.0.3", + "sebastian/environment": "^5.1.3", + "sebastian/exporter": "^4.0.5", + "sebastian/global-state": "^5.0.1", + "sebastian/object-enumerator": "^4.0.3", + "sebastian/resource-operations": "^3.0.3", + "sebastian/type": "^3.2", + "sebastian/version": "^3.0.2" + }, + "suggest": { + "ext-soap": "To be able to generate mocks based on WSDL files", + "ext-xdebug": "PHP extension that provides line coverage as well as branch and path coverage" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "9.6-dev" + } + }, + "autoload": { + "files": [ + "src/Framework/Assert/Functions.php" + ], + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/phpunit/issues", + "security": "https://github.com/sebastianbergmann/phpunit/security/policy", + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.18" + }, + "funding": [ + { + "url": "https://phpunit.de/sponsors.html", + "type": "custom" + }, + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpunit/phpunit", + "type": "tidelift" + } + ], + "time": "2024-03-21T12:07:32+00:00" + }, + { + "name": "sebastian/cli-parser", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/cli-parser.git", + "reference": "2b56bea83a09de3ac06bb18b92f068e60cc6f50b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/2b56bea83a09de3ac06bb18b92f068e60cc6f50b", + "reference": "2b56bea83a09de3ac06bb18b92f068e60cc6f50b", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for parsing CLI options", + "homepage": "https://github.com/sebastianbergmann/cli-parser", + "support": { + "issues": "https://github.com/sebastianbergmann/cli-parser/issues", + "source": "https://github.com/sebastianbergmann/cli-parser/tree/1.0.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-03-02T06:27:43+00:00" + }, + { + "name": "sebastian/code-unit", + "version": "1.0.8", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit.git", + "reference": "1fc9f64c0927627ef78ba436c9b17d967e68e120" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit/zipball/1fc9f64c0927627ef78ba436c9b17d967e68e120", + "reference": "1fc9f64c0927627ef78ba436c9b17d967e68e120", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Collection of value objects that represent the PHP code units", + "homepage": "https://github.com/sebastianbergmann/code-unit", + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit/issues", + "source": "https://github.com/sebastianbergmann/code-unit/tree/1.0.8" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-10-26T13:08:54+00:00" + }, + { + "name": "sebastian/code-unit-reverse-lookup", + "version": "2.0.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", + "reference": "ac91f01ccec49fb77bdc6fd1e548bc70f7faa3e5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/ac91f01ccec49fb77bdc6fd1e548bc70f7faa3e5", + "reference": "ac91f01ccec49fb77bdc6fd1e548bc70f7faa3e5", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Looks up which function or method a line of code belongs to", + "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/issues", + "source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/2.0.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-09-28T05:30:19+00:00" + }, + { + "name": "sebastian/comparator", + "version": "4.0.8", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "fa0f136dd2334583309d32b62544682ee972b51a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/fa0f136dd2334583309d32b62544682ee972b51a", + "reference": "fa0f136dd2334583309d32b62544682ee972b51a", + "shasum": "" + }, + "require": { + "php": ">=7.3", + "sebastian/diff": "^4.0", + "sebastian/exporter": "^4.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "https://github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/comparator/issues", + "source": "https://github.com/sebastianbergmann/comparator/tree/4.0.8" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2022-09-14T12:41:17+00:00" + }, + { + "name": "sebastian/complexity", + "version": "2.0.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/complexity.git", + "reference": "25f207c40d62b8b7aa32f5ab026c53561964053a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/25f207c40d62b8b7aa32f5ab026c53561964053a", + "reference": "25f207c40d62b8b7aa32f5ab026c53561964053a", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^4.18 || ^5.0", + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for calculating the complexity of PHP code units", + "homepage": "https://github.com/sebastianbergmann/complexity", + "support": { + "issues": "https://github.com/sebastianbergmann/complexity/issues", + "source": "https://github.com/sebastianbergmann/complexity/tree/2.0.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-12-22T06:19:30+00:00" + }, + { + "name": "sebastian/diff", + "version": "4.0.6", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "ba01945089c3a293b01ba9badc29ad55b106b0bc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/ba01945089c3a293b01ba9badc29ad55b106b0bc", + "reference": "ba01945089c3a293b01ba9badc29ad55b106b0bc", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3", + "symfony/process": "^4.2 || ^5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + } + ], + "description": "Diff implementation", + "homepage": "https://github.com/sebastianbergmann/diff", + "keywords": [ + "diff", + "udiff", + "unidiff", + "unified diff" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/diff/issues", + "source": "https://github.com/sebastianbergmann/diff/tree/4.0.6" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-03-02T06:30:58+00:00" + }, + { + "name": "sebastian/environment", + "version": "5.1.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "830c43a844f1f8d5b7a1f6d6076b784454d8b7ed" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/830c43a844f1f8d5b7a1f6d6076b784454d8b7ed", + "reference": "830c43a844f1f8d5b7a1f6d6076b784454d8b7ed", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "suggest": { + "ext-posix": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "http://www.github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/environment/issues", + "source": "https://github.com/sebastianbergmann/environment/tree/5.1.5" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:03:51+00:00" + }, + { + "name": "sebastian/exporter", + "version": "4.0.6", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "78c00df8f170e02473b682df15bfcdacc3d32d72" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/78c00df8f170e02473b682df15bfcdacc3d32d72", + "reference": "78c00df8f170e02473b682df15bfcdacc3d32d72", + "shasum": "" + }, + "require": { + "php": ">=7.3", + "sebastian/recursion-context": "^4.0" + }, + "require-dev": { + "ext-mbstring": "*", + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "https://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/exporter/issues", + "source": "https://github.com/sebastianbergmann/exporter/tree/4.0.6" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-03-02T06:33:00+00:00" + }, + { + "name": "sebastian/global-state", + "version": "5.0.7", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "bca7df1f32ee6fe93b4d4a9abbf69e13a4ada2c9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bca7df1f32ee6fe93b4d4a9abbf69e13a4ada2c9", + "reference": "bca7df1f32ee6fe93b4d4a9abbf69e13a4ada2c9", + "shasum": "" + }, + "require": { + "php": ">=7.3", + "sebastian/object-reflector": "^2.0", + "sebastian/recursion-context": "^4.0" + }, + "require-dev": { + "ext-dom": "*", + "phpunit/phpunit": "^9.3" + }, + "suggest": { + "ext-uopz": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Snapshotting of global state", + "homepage": "http://www.github.com/sebastianbergmann/global-state", + "keywords": [ + "global state" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/global-state/issues", + "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.7" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-03-02T06:35:11+00:00" + }, + { + "name": "sebastian/lines-of-code", + "version": "1.0.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/lines-of-code.git", + "reference": "e1e4a170560925c26d424b6a03aed157e7dcc5c5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/e1e4a170560925c26d424b6a03aed157e7dcc5c5", + "reference": "e1e4a170560925c26d424b6a03aed157e7dcc5c5", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^4.18 || ^5.0", + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for counting the lines of code in PHP source code", + "homepage": "https://github.com/sebastianbergmann/lines-of-code", + "support": { + "issues": "https://github.com/sebastianbergmann/lines-of-code/issues", + "source": "https://github.com/sebastianbergmann/lines-of-code/tree/1.0.4" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-12-22T06:20:34+00:00" + }, + { + "name": "sebastian/object-enumerator", + "version": "4.0.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-enumerator.git", + "reference": "5c9eeac41b290a3712d88851518825ad78f45c71" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/5c9eeac41b290a3712d88851518825ad78f45c71", + "reference": "5c9eeac41b290a3712d88851518825ad78f45c71", + "shasum": "" + }, + "require": { + "php": ">=7.3", + "sebastian/object-reflector": "^2.0", + "sebastian/recursion-context": "^4.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Traverses array structures and object graphs to enumerate all referenced objects", + "homepage": "https://github.com/sebastianbergmann/object-enumerator/", + "support": { + "issues": "https://github.com/sebastianbergmann/object-enumerator/issues", + "source": "https://github.com/sebastianbergmann/object-enumerator/tree/4.0.4" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-10-26T13:12:34+00:00" + }, + { + "name": "sebastian/object-reflector", + "version": "2.0.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-reflector.git", + "reference": "b4f479ebdbf63ac605d183ece17d8d7fe49c15c7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/b4f479ebdbf63ac605d183ece17d8d7fe49c15c7", + "reference": "b4f479ebdbf63ac605d183ece17d8d7fe49c15c7", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Allows reflection of object attributes, including inherited and non-public ones", + "homepage": "https://github.com/sebastianbergmann/object-reflector/", + "support": { + "issues": "https://github.com/sebastianbergmann/object-reflector/issues", + "source": "https://github.com/sebastianbergmann/object-reflector/tree/2.0.4" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-10-26T13:14:26+00:00" + }, + { + "name": "sebastian/recursion-context", + "version": "4.0.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1", + "reference": "e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "https://github.com/sebastianbergmann/recursion-context", + "support": { + "issues": "https://github.com/sebastianbergmann/recursion-context/issues", + "source": "https://github.com/sebastianbergmann/recursion-context/tree/4.0.5" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:07:39+00:00" + }, + { + "name": "sebastian/resource-operations", + "version": "3.0.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/resource-operations.git", + "reference": "05d5692a7993ecccd56a03e40cd7e5b09b1d404e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/05d5692a7993ecccd56a03e40cd7e5b09b1d404e", + "reference": "05d5692a7993ecccd56a03e40cd7e5b09b1d404e", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides a list of PHP built-in functions that operate on resources", + "homepage": "https://www.github.com/sebastianbergmann/resource-operations", + "support": { + "source": "https://github.com/sebastianbergmann/resource-operations/tree/3.0.4" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-03-14T16:00:52+00:00" + }, + { + "name": "sebastian/type", + "version": "3.2.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/type.git", + "reference": "75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7", + "reference": "75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Collection of value objects that represent the types of the PHP type system", + "homepage": "https://github.com/sebastianbergmann/type", + "support": { + "issues": "https://github.com/sebastianbergmann/type/issues", + "source": "https://github.com/sebastianbergmann/type/tree/3.2.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:13:03+00:00" + }, + { + "name": "sebastian/version", + "version": "3.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "c6c1022351a901512170118436c764e473f6de8c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/c6c1022351a901512170118436c764e473f6de8c", + "reference": "c6c1022351a901512170118436c764e473f6de8c", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "support": { + "issues": "https://github.com/sebastianbergmann/version/issues", + "source": "https://github.com/sebastianbergmann/version/tree/3.0.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-09-28T06:39:44+00:00" + }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.9.1", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", + "reference": "267a4405fff1d9c847134db3a3c92f1ab7f77909" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/267a4405fff1d9c847134db3a3c92f1ab7f77909", + "reference": "267a4405fff1d9c847134db3a3c92f1ab7f77909", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" + }, + "bin": [ + "bin/phpcbf", + "bin/phpcs" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "Former lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "Current lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/PHP_CodeSniffer/issues", + "security": "https://github.com/PHPCSStandards/PHP_CodeSniffer/security/policy", + "source": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "wiki": "https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki" + }, + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + } + ], + "time": "2024-03-31T21:03:09+00:00" + }, + { + "name": "symfony/polyfill-php73", + "version": "v1.29.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php73.git", + "reference": "21bd091060673a1177ae842c0ef8fe30893114d2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/21bd091060673a1177ae842c0ef8fe30893114d2", + "reference": "21bd091060673a1177ae842c0ef8fe30893114d2", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "type": "library", + "extra": { + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Php73\\": "" + }, + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-php73/tree/v1.29.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-01-29T20:11:03+00:00" + }, + { + "name": "szepeviktor/phpstan-wordpress", + "version": "v1.3.4", + "source": { + "type": "git", + "url": "https://github.com/szepeviktor/phpstan-wordpress.git", + "reference": "891d0767855a32c886a439efae090408cc1fa156" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/szepeviktor/phpstan-wordpress/zipball/891d0767855a32c886a439efae090408cc1fa156", + "reference": "891d0767855a32c886a439efae090408cc1fa156", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0", + "php-stubs/wordpress-stubs": "^4.7 || ^5.0 || ^6.0", + "phpstan/phpstan": "^1.10.31", + "symfony/polyfill-php73": "^1.12.0" + }, + "require-dev": { + "composer/composer": "^2.1.14", + "dealerdirect/phpcodesniffer-composer-installer": "^1.0", + "php-parallel-lint/php-parallel-lint": "^1.1", + "phpstan/phpstan-strict-rules": "^1.2", + "phpunit/phpunit": "^8.0 || ^9.0", + "szepeviktor/phpcs-psr-12-neutron-hybrid-ruleset": "^0.8" + }, + "suggest": { + "swissspidy/phpstan-no-private": "Detect usage of internal core functions, classes and methods" + }, + "type": "phpstan-extension", + "extra": { + "phpstan": { + "includes": [ + "extension.neon" + ] + } + }, + "autoload": { + "psr-4": { + "SzepeViktor\\PHPStan\\WordPress\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "WordPress extensions for PHPStan", + "keywords": [ + "PHPStan", + "code analyse", + "code analysis", + "static analysis", + "wordpress" + ], + "support": { + "issues": "https://github.com/szepeviktor/phpstan-wordpress/issues", + "source": "https://github.com/szepeviktor/phpstan-wordpress/tree/v1.3.4" + }, + "time": "2024-03-21T16:32:59+00:00" + }, + { + "name": "theseer/tokenizer", + "version": "1.2.3", + "source": { + "type": "git", + "url": "https://github.com/theseer/tokenizer.git", + "reference": "737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2", + "reference": "737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": "^7.2 || ^8.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + } + ], + "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", + "support": { + "issues": "https://github.com/theseer/tokenizer/issues", + "source": "https://github.com/theseer/tokenizer/tree/1.2.3" + }, + "funding": [ + { + "url": "https://github.com/theseer", + "type": "github" + } + ], + "time": "2024-03-03T12:36:25+00:00" + }, + { + "name": "wp-coding-standards/wpcs", + "version": "3.1.0", + "source": { + "type": "git", + "url": "https://github.com/WordPress/WordPress-Coding-Standards.git", + "reference": "9333efcbff231f10dfd9c56bb7b65818b4733ca7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/9333efcbff231f10dfd9c56bb7b65818b4733ca7", + "reference": "9333efcbff231f10dfd9c56bb7b65818b4733ca7", + "shasum": "" + }, + "require": { + "ext-filter": "*", + "ext-libxml": "*", + "ext-tokenizer": "*", + "ext-xmlreader": "*", + "php": ">=5.4", + "phpcsstandards/phpcsextra": "^1.2.1", + "phpcsstandards/phpcsutils": "^1.0.10", + "squizlabs/php_codesniffer": "^3.9.0" + }, + "require-dev": { + "php-parallel-lint/php-console-highlighter": "^1.0.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "phpcompatibility/php-compatibility": "^9.0", + "phpcsstandards/phpcsdevtools": "^1.2.0", + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0" + }, + "suggest": { + "ext-iconv": "For improved results", + "ext-mbstring": "For improved results" + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Contributors", + "homepage": "https://github.com/WordPress/WordPress-Coding-Standards/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions", + "keywords": [ + "phpcs", + "standards", + "static analysis", + "wordpress" + ], + "support": { + "issues": "https://github.com/WordPress/WordPress-Coding-Standards/issues", + "source": "https://github.com/WordPress/WordPress-Coding-Standards", + "wiki": "https://github.com/WordPress/WordPress-Coding-Standards/wiki" + }, + "funding": [ + { + "url": "https://opencollective.com/php_codesniffer", + "type": "custom" + } + ], + "time": "2024-03-25T16:39:00+00:00" + }, + { + "name": "yoast/phpunit-polyfills", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/Yoast/PHPUnit-Polyfills.git", + "reference": "224e4a1329c03d8bad520e3fc4ec980034a4b212" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Yoast/PHPUnit-Polyfills/zipball/224e4a1329c03d8bad520e3fc4ec980034a4b212", + "reference": "224e4a1329c03d8bad520e3fc4ec980034a4b212", + "shasum": "" + }, + "require": { + "php": ">=5.4", + "phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0" + }, + "require-dev": { + "yoast/yoastcs": "^2.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "2.x-dev" + } + }, + "autoload": { + "files": [ + "phpunitpolyfills-autoload.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Team Yoast", + "email": "support@yoast.com", + "homepage": "https://yoast.com" + }, + { + "name": "Contributors", + "homepage": "https://github.com/Yoast/PHPUnit-Polyfills/graphs/contributors" + } + ], + "description": "Set of polyfills for changed PHPUnit functionality to allow for creating PHPUnit cross-version compatible tests", + "homepage": "https://github.com/Yoast/PHPUnit-Polyfills", + "keywords": [ + "phpunit", + "polyfill", + "testing" + ], + "support": { + "issues": "https://github.com/Yoast/PHPUnit-Polyfills/issues", + "source": "https://github.com/Yoast/PHPUnit-Polyfills" + }, + "time": "2023-08-19T14:25:08+00:00" + }, + { + "name": "yoast/wp-test-utils", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/Yoast/wp-test-utils.git", + "reference": "2e0f62e0281e4859707c5f13b7da1422aa1c8f7b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Yoast/wp-test-utils/zipball/2e0f62e0281e4859707c5f13b7da1422aa1c8f7b", + "reference": "2e0f62e0281e4859707c5f13b7da1422aa1c8f7b", + "shasum": "" + }, + "require": { + "brain/monkey": "^2.6.1", + "php": ">=5.6", + "yoast/phpunit-polyfills": "^1.1.0" + }, + "require-dev": { + "yoast/yoastcs": "^2.3.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-develop": "1.x-dev", + "dev-main": "1.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ], + "exclude-from-classmap": [ + "/src/WPIntegration/TestCase.php", + "/src/WPIntegration/TestCaseNoPolyfills.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Team Yoast", + "email": "support@yoast.com", + "homepage": "https://yoast.com" + }, + { + "name": "Contributors", + "homepage": "https://github.com/Yoast/wp-test-utils/graphs/contributors" + } + ], + "description": "PHPUnit cross-version compatibility layer for testing plugins and themes build for WordPress", + "homepage": "https://github.com/Yoast/wp-test-utils/", + "keywords": [ + "brainmonkey", + "integration-testing", + "phpunit", + "testing", + "unit-testing", + "wordpress" + ], + "support": { + "issues": "https://github.com/Yoast/wp-test-utils/issues", + "source": "https://github.com/Yoast/wp-test-utils" + }, + "time": "2023-09-27T10:25:08+00:00" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [], + "plugin-api-version": "2.6.0" +} From 2295cfddee609151df063744990b579f7e9e0ca4 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 5 Apr 2024 09:03:51 +0300 Subject: [PATCH 313/490] Update includes/class-activity.php Co-authored-by: Joost de Valk --- includes/class-activity.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/class-activity.php b/includes/class-activity.php index aaaaaa11e..f1487609b 100644 --- a/includes/class-activity.php +++ b/includes/class-activity.php @@ -201,9 +201,9 @@ public function save() { ); if ( ! empty( $existing ) ) { \progress_planner()->get_query()->update_activity( $existing[0]->id, $this ); - } else { - \progress_planner()->get_query()->insert_activity( $this ); + return; } + \progress_planner()->get_query()->insert_activity( $this ); } /** From 72ba38bb08657d999ad2d841b2172eb35eba3015 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 5 Apr 2024 09:04:15 +0300 Subject: [PATCH 314/490] Update includes/actions/class-content.php Co-authored-by: Joost de Valk --- includes/actions/class-content.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/actions/class-content.php b/includes/actions/class-content.php index 3a40bf0eb..22bc56865 100644 --- a/includes/actions/class-content.php +++ b/includes/actions/class-content.php @@ -110,7 +110,7 @@ public function insert_post( $post_id, $post ) { return; } - // Check if there is an publish activity for this post. + // Check if there is a publish activity for this post. $existing = \progress_planner()->get_query()->query_activities( [ 'category' => 'content', From 06123f9083d58d75ade6ebbbc224167fe05d6b57 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 5 Apr 2024 09:05:18 +0300 Subject: [PATCH 315/490] Move inline styles to stylesheet --- assets/css/admin.css | 1 + includes/class-chart.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/assets/css/admin.css b/assets/css/admin.css index 617f0aa86..aa892783a 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -87,6 +87,7 @@ .prpl-chart-container { position: relative; height: 100%; + width: 100%; max-height: 500px; } diff --git a/includes/class-chart.php b/includes/class-chart.php index 0b481291a..9eba067ab 100644 --- a/includes/class-chart.php +++ b/includes/class-chart.php @@ -235,7 +235,7 @@ public function render_chart_js( $id, $type, $data, $options = [] ) { $id = 'progress-planner-chart-' . $id; ?> -
+