Loading datetime-chart.php 0 → 100644 +50 −0 Original line number Diff line number Diff line <div class="wc-stats-chart"> <p> <strong>Words in <?php echo $post_type; ?>s by <?php echo $dt_unit; ?></strong> </p> <div class="wc-chart" id="wc-<?php echo $post_type; ?>-<?php echo $dt_unit; ?>-count" ></div> <script type="text/javascript"> var options = { chart: { type: 'line' }, series: [ { name: 'Word count', data: [ <?php $i = 0; foreach (array_keys($unit_count) as $unit) { $yc = $unit_count[$unit]; if ($dt_unit == 'year') echo "{ x: new Date('$unit-06-30').getTime(), y: $yc },"; else echo "{ x: new Date('$unit-15').getTime(), y: $yc },"; } ?> ] } ], xaxis: { type: 'datetime', labels: { formatter: function (val, opts) { <?php echo $label_jscode; ?> } } }, yaxis: { labels: { formatter: function (val, opts) { return new Intl.NumberFormat().format(val); } } }, tooltip: { y: { formatter: function (val, opts) { return new Intl.NumberFormat().format(val); } } } } var chart = new ApexCharts(document.querySelector("#wc-<?php echo $post_type; ?>-<?php echo $dt_unit; ?>-count"), options); chart.render(); </script> </div> page.php +7 −5 Original line number Diff line number Diff line Loading @@ -6,11 +6,10 @@ define('WC_ROWS_PER_PAGE', 20); global $wpdb; function get_wc_tab() { $wc_tab = !empty($_GET["wc-tab"]) ? $_GET["wc-tab"] : 'tab-tables'; if ($wc_tab != 'tab-tables' && $wc_tab != 'tab-barcharts' && $wc_tab != 'tab-piecharts') { $wc_tab = 'tab-tables'; $wc_tab = !empty($_GET["wc-tab"]) ? $_GET["wc-tab"] : 'tab-stats'; if ($wc_tab != 'tab-stats' && $wc_tab != 'tab-tables' && $wc_tab != 'tab-barcharts' && $wc_tab != 'tab-piecharts') { $wc_tab = 'tab-stats'; } return $wc_tab; } Loading Loading @@ -115,6 +114,9 @@ wc.launchInterval(); <?php } else { switch (get_wc_tab()) { case 'tab-stats': include_once WORD_COUNT__PLUGIN_DIR . '/tab-stats.php'; break; case 'tab-tables': include_once WORD_COUNT__PLUGIN_DIR . '/tab-tables.php'; break; Loading stats.php 0 → 100644 +52 −0 Original line number Diff line number Diff line <?php $wc_page = !empty($_GET["wc-$post_type-page"]) ? intval($_GET["wc-$post_type-page"]) : 0; $sql = $wpdb->prepare(" SELECT wp_posts.id AS id, wp_posts.post_date AS date, wp_posts.post_title AS title, CAST(wp_postmeta.meta_value AS UNSIGNED) AS word_count FROM wp_posts, wp_postmeta WHERE wp_posts.id = wp_postmeta.post_id AND wp_posts.post_status = 'publish' AND wp_postmeta.meta_key = 'word-count' AND wp_posts.post_type = %s ORDER BY post_date", $post_type); $results = $wpdb->get_results($sql); $wc_total = 0; $year_count = array(); $month_count = array(); foreach ($results as $result) { $year = intval(substr($result->date, 0, 4)); $month = substr($result->date, 0, 7); if (!array_key_exists($year, $year_count)) { $year_count[$year] = 0; } if (!array_key_exists($month, $month_count)) { $month_count[$month] = 0; } $year_count[$year] = $year_count[$year] + $result->word_count; $month_count[$month] = $month_count[$month] + $result->word_count; $wc_total += $result->word_count; } ?> <div class="wc_section"> <h3><?php echo $sec_title; ?></h3> <div class="wc-stats-container"> <?php $dt_unit = 'year'; $unit_count = $year_count; $label_jscode = 'return new Date(val).getFullYear();'; include WORD_COUNT__PLUGIN_DIR . '/datetime-chart.php'; $dt_unit = 'month'; $unit_count = $month_count; $label_jscode = 'var dt = new Date(val);' . 'var year = dt.getFullYear();' . 'var month = dt.getMonth()+1;' . 'return year + "/" + (("00" + month).slice(-2));'; include WORD_COUNT__PLUGIN_DIR . '/datetime-chart.php'; ?> </div> </div> style.css +72 −17 Original line number Diff line number Diff line .wc_box { display: flex; flex-wrap: wrap; padding: 4px 4px; } .wc_chart { border: 1px solid #000; padding: 10px; table.wc-table { max-width: 800px; background-color: #fff; } table.wc_table { width: 600px; } table.wc_table, th, td { table.wc-table, th, td { border: 1px solid black; border-collapse: collapse; } Loading Loading @@ -42,6 +32,7 @@ th.left { .wc-tabs-headers { font-size: large; font-weight: bold; height: 50px; } .wc-tab-header > a, Loading @@ -49,15 +40,19 @@ th.left { .wc-tab-header > a:visited, .wc-tab-header > a:hover, .wc-tab-header > a:active { display: flex; align-items: center; justify-content: center; height: 50px; background-color: #777; color: #eee; text-decoration: none; } .wc-tab-header { display: inline-block; width: 150px; height: 100px; padding: 15px; height: 50px; background-color: #777; color: #eee; border: 1px solid #000; Loading @@ -74,9 +69,69 @@ th.left { } .wc-tab-content { margin-top: 20px; margin-top: 1px; padding: 20px; padding-top: 0px; border: 1px solid #000; background-color: #fafafa; } div.wc-input { max-width: 800px; margin-top: 10px; } .wc-filter { width: 100%; } div#wc-post-barchart { max-width: 1200px; } div#wc-page-barchart { max-width: 1200px; } div#wc-post-piechart { max-width: 1200px; } div#wc-page-piechart { max-width: 1200px; } div#wc-post-year-count { max-width: 800px; } div#wc-page-year-count { max-width: 800px; } div#wc-post-month-count { max-width: 800px; } div#wc-page-month-count { max-width: 800px; } .wc-stats-container { display: flex; max-width: 1680px; } .wc-stats-chart { flex: 1; } .wc-stats-chart:first-child { margin-right: 50px; } .wc-chart { padding: 10px; border: 1px solid black; background-color: #fff; } tab-barcharts.php +3 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,9 @@ $taburl = get_site_url() . '/wp-admin/plugins.php?page=word-count&wc-tab=' <h2>Word count and statistics for posts and pages</h2> <div class="wc-tabs"> <div class="wc-tabs-headers"> <span class ="wc-tab-header"> <a href="<?php echo $taburl;?>tab-stats">Statistics</a> </span> <span class ="wc-tab-header"> <a href="<?php echo $taburl;?>tab-tables">Tables</a> </span> Loading Loading
datetime-chart.php 0 → 100644 +50 −0 Original line number Diff line number Diff line <div class="wc-stats-chart"> <p> <strong>Words in <?php echo $post_type; ?>s by <?php echo $dt_unit; ?></strong> </p> <div class="wc-chart" id="wc-<?php echo $post_type; ?>-<?php echo $dt_unit; ?>-count" ></div> <script type="text/javascript"> var options = { chart: { type: 'line' }, series: [ { name: 'Word count', data: [ <?php $i = 0; foreach (array_keys($unit_count) as $unit) { $yc = $unit_count[$unit]; if ($dt_unit == 'year') echo "{ x: new Date('$unit-06-30').getTime(), y: $yc },"; else echo "{ x: new Date('$unit-15').getTime(), y: $yc },"; } ?> ] } ], xaxis: { type: 'datetime', labels: { formatter: function (val, opts) { <?php echo $label_jscode; ?> } } }, yaxis: { labels: { formatter: function (val, opts) { return new Intl.NumberFormat().format(val); } } }, tooltip: { y: { formatter: function (val, opts) { return new Intl.NumberFormat().format(val); } } } } var chart = new ApexCharts(document.querySelector("#wc-<?php echo $post_type; ?>-<?php echo $dt_unit; ?>-count"), options); chart.render(); </script> </div>
page.php +7 −5 Original line number Diff line number Diff line Loading @@ -6,11 +6,10 @@ define('WC_ROWS_PER_PAGE', 20); global $wpdb; function get_wc_tab() { $wc_tab = !empty($_GET["wc-tab"]) ? $_GET["wc-tab"] : 'tab-tables'; if ($wc_tab != 'tab-tables' && $wc_tab != 'tab-barcharts' && $wc_tab != 'tab-piecharts') { $wc_tab = 'tab-tables'; $wc_tab = !empty($_GET["wc-tab"]) ? $_GET["wc-tab"] : 'tab-stats'; if ($wc_tab != 'tab-stats' && $wc_tab != 'tab-tables' && $wc_tab != 'tab-barcharts' && $wc_tab != 'tab-piecharts') { $wc_tab = 'tab-stats'; } return $wc_tab; } Loading Loading @@ -115,6 +114,9 @@ wc.launchInterval(); <?php } else { switch (get_wc_tab()) { case 'tab-stats': include_once WORD_COUNT__PLUGIN_DIR . '/tab-stats.php'; break; case 'tab-tables': include_once WORD_COUNT__PLUGIN_DIR . '/tab-tables.php'; break; Loading
stats.php 0 → 100644 +52 −0 Original line number Diff line number Diff line <?php $wc_page = !empty($_GET["wc-$post_type-page"]) ? intval($_GET["wc-$post_type-page"]) : 0; $sql = $wpdb->prepare(" SELECT wp_posts.id AS id, wp_posts.post_date AS date, wp_posts.post_title AS title, CAST(wp_postmeta.meta_value AS UNSIGNED) AS word_count FROM wp_posts, wp_postmeta WHERE wp_posts.id = wp_postmeta.post_id AND wp_posts.post_status = 'publish' AND wp_postmeta.meta_key = 'word-count' AND wp_posts.post_type = %s ORDER BY post_date", $post_type); $results = $wpdb->get_results($sql); $wc_total = 0; $year_count = array(); $month_count = array(); foreach ($results as $result) { $year = intval(substr($result->date, 0, 4)); $month = substr($result->date, 0, 7); if (!array_key_exists($year, $year_count)) { $year_count[$year] = 0; } if (!array_key_exists($month, $month_count)) { $month_count[$month] = 0; } $year_count[$year] = $year_count[$year] + $result->word_count; $month_count[$month] = $month_count[$month] + $result->word_count; $wc_total += $result->word_count; } ?> <div class="wc_section"> <h3><?php echo $sec_title; ?></h3> <div class="wc-stats-container"> <?php $dt_unit = 'year'; $unit_count = $year_count; $label_jscode = 'return new Date(val).getFullYear();'; include WORD_COUNT__PLUGIN_DIR . '/datetime-chart.php'; $dt_unit = 'month'; $unit_count = $month_count; $label_jscode = 'var dt = new Date(val);' . 'var year = dt.getFullYear();' . 'var month = dt.getMonth()+1;' . 'return year + "/" + (("00" + month).slice(-2));'; include WORD_COUNT__PLUGIN_DIR . '/datetime-chart.php'; ?> </div> </div>
style.css +72 −17 Original line number Diff line number Diff line .wc_box { display: flex; flex-wrap: wrap; padding: 4px 4px; } .wc_chart { border: 1px solid #000; padding: 10px; table.wc-table { max-width: 800px; background-color: #fff; } table.wc_table { width: 600px; } table.wc_table, th, td { table.wc-table, th, td { border: 1px solid black; border-collapse: collapse; } Loading Loading @@ -42,6 +32,7 @@ th.left { .wc-tabs-headers { font-size: large; font-weight: bold; height: 50px; } .wc-tab-header > a, Loading @@ -49,15 +40,19 @@ th.left { .wc-tab-header > a:visited, .wc-tab-header > a:hover, .wc-tab-header > a:active { display: flex; align-items: center; justify-content: center; height: 50px; background-color: #777; color: #eee; text-decoration: none; } .wc-tab-header { display: inline-block; width: 150px; height: 100px; padding: 15px; height: 50px; background-color: #777; color: #eee; border: 1px solid #000; Loading @@ -74,9 +69,69 @@ th.left { } .wc-tab-content { margin-top: 20px; margin-top: 1px; padding: 20px; padding-top: 0px; border: 1px solid #000; background-color: #fafafa; } div.wc-input { max-width: 800px; margin-top: 10px; } .wc-filter { width: 100%; } div#wc-post-barchart { max-width: 1200px; } div#wc-page-barchart { max-width: 1200px; } div#wc-post-piechart { max-width: 1200px; } div#wc-page-piechart { max-width: 1200px; } div#wc-post-year-count { max-width: 800px; } div#wc-page-year-count { max-width: 800px; } div#wc-post-month-count { max-width: 800px; } div#wc-page-month-count { max-width: 800px; } .wc-stats-container { display: flex; max-width: 1680px; } .wc-stats-chart { flex: 1; } .wc-stats-chart:first-child { margin-right: 50px; } .wc-chart { padding: 10px; border: 1px solid black; background-color: #fff; }
tab-barcharts.php +3 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,9 @@ $taburl = get_site_url() . '/wp-admin/plugins.php?page=word-count&wc-tab=' <h2>Word count and statistics for posts and pages</h2> <div class="wc-tabs"> <div class="wc-tabs-headers"> <span class ="wc-tab-header"> <a href="<?php echo $taburl;?>tab-stats">Statistics</a> </span> <span class ="wc-tab-header"> <a href="<?php echo $taburl;?>tab-tables">Tables</a> </span> Loading