statistics.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <?php
  2. if (!defined('ABSPATH'))
  3. exit;
  4. @include_once NEWSLETTER_INCLUDES_DIR . '/controls.php';
  5. wp_enqueue_script('tnp-chart');
  6. $all_count = $wpdb->get_var("select count(*) from " . NEWSLETTER_USERS_TABLE);
  7. $options_profile = get_option('newsletter_profile');
  8. $module = NewsletterUsers::instance();
  9. $controls = new NewsletterControls();
  10. ?>
  11. <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
  12. <script type="text/javascript">
  13. google.charts.load("current", {packages: ['corechart', 'geochart', 'geomap']});
  14. </script>
  15. <div class="wrap" id="tnp-wrap">
  16. <?php include NEWSLETTER_DIR . '/tnp-header.php'; ?>
  17. <div id="tnp-heading">
  18. <h2><?php _e('Subscriber statistics', 'newsletter') ?></h2>
  19. </div>
  20. <div id="tnp-body" class="tnp-users-statistics">
  21. <?php $controls->init(); ?>
  22. <div id="tabs">
  23. <ul>
  24. <li><a href="#tab-overview">Overview</a></li>
  25. <li><a href="#tabs-lists">Lists</a></li>
  26. <li><a href="#tabs-countries">World Map</a></li>
  27. <li><a href="#tabs-referrers">Referrer</a></li>
  28. <li><a href="#tabs-sources">Sources</a></li>
  29. <li><a href="#tabs-gender">Gender</a></li>
  30. <li><a href="#tabs-time">By time</a></li>
  31. </ul>
  32. <div id="tab-overview">
  33. <table class="widefat" style="width: auto">
  34. <thead>
  35. <tr>
  36. <th><?php _e('Status', 'newsletter') ?></th>
  37. <th><?php _e('Total', 'newsletter') ?></th>
  38. </tr>
  39. </thead>
  40. <tbody>
  41. <tr>
  42. <td><?php _e('Any', 'newsletter') ?></td>
  43. <td>
  44. <?php echo $wpdb->get_var("select count(*) from " . NEWSLETTER_USERS_TABLE); ?>
  45. </td>
  46. </tr>
  47. <tr>
  48. <td><?php _e('Confirmed', 'newsletter') ?></td>
  49. <td>
  50. <?php echo $wpdb->get_var("select count(*) from " . NEWSLETTER_USERS_TABLE . " where status='C'"); ?>
  51. </td>
  52. </tr>
  53. <tr>
  54. <td><?php _e('Not confirmed', 'newsletter') ?></td>
  55. <td>
  56. <?php echo $wpdb->get_var("select count(*) from " . NEWSLETTER_USERS_TABLE . " where status='S'"); ?>
  57. </td>
  58. </tr>
  59. <tr>
  60. <td><?php _e('Unsubscribed', 'newsletter') ?></td>
  61. <td>
  62. <?php echo $wpdb->get_var("select count(*) from " . NEWSLETTER_USERS_TABLE . " where status='U'"); ?>
  63. </td>
  64. </tr>
  65. <tr>
  66. <td><?php _e('Bounced', 'newsletter') ?></td>
  67. <td>
  68. <?php echo $wpdb->get_var("select count(*) from " . NEWSLETTER_USERS_TABLE . " where status='B'"); ?>
  69. </td>
  70. </tr>
  71. </tbody>
  72. </table>
  73. <?php if ($module->is_multilanguage()) { ?>
  74. <h3>By language</h3>
  75. <?php $languages = $module->get_languages(); ?>
  76. <table class="widefat" style="width: auto">
  77. <thead>
  78. <tr>
  79. <th><?php _e('Status', 'newsletter') ?></th>
  80. <th><?php _e('Total', 'newsletter') ?></th>
  81. </tr>
  82. <tbody>
  83. <?php foreach ($languages as $code=>$label) { ?>
  84. <tr>
  85. <td><?php echo esc_html($label) ?></td>
  86. <td>
  87. <?php echo $wpdb->get_var($wpdb->prepare("select count(*) from " . NEWSLETTER_USERS_TABLE . " where language=%s", $code)); ?>
  88. </td>
  89. </tr>
  90. <?php } ?>
  91. <tr>
  92. <td><?php _e('Without language', 'newsletter') ?></td>
  93. <td>
  94. <?php echo $wpdb->get_var("select count(*) from " . NEWSLETTER_USERS_TABLE . " where language=''"); ?>
  95. </td>
  96. </tr>
  97. </thead>
  98. </tbody>
  99. </table>
  100. <?php } ?>
  101. </div>
  102. <div id="tabs-lists">
  103. <table class="widefat" style="width: auto">
  104. <thead>
  105. <tr>
  106. <th>&nbsp;</th>
  107. <th><?php _e('List', 'newsletter') ?></th>
  108. <th><?php _e('Total', 'newsletter') ?> (*)</th>
  109. </tr>
  110. </thead>
  111. <tbody>
  112. <?php $lists = $module->get_lists(); ?>
  113. <?php foreach ($lists as $list) { ?>
  114. <tr>
  115. <td><?php echo $list->id ?></td>
  116. <td><?php echo esc_html($list->name) ?></td>
  117. <td>
  118. <?php echo $wpdb->get_var("select count(*) from " . NEWSLETTER_USERS_TABLE . " where list_" . $list->id . "=1 and status='C'"); ?>
  119. </td>
  120. </tr>
  121. <?php } ?>
  122. </tbody>
  123. </table>
  124. (*) <?php _e('Confirmed', 'newsletter') ?>
  125. </div>
  126. <div id="tabs-countries">
  127. <?php
  128. if (!has_action('newsletter_users_statistics_countries')) {
  129. include __DIR__ . '/statistics-countries.php';
  130. } else {
  131. do_action('newsletter_users_statistics_countries', $controls);
  132. }
  133. ?>
  134. </div>
  135. <div id="tabs-referrers">
  136. <p>
  137. <?php $controls->panel_help('https://www.thenewsletterplugin.com/documentation/subscribers-statistics#referrer') ?>
  138. </p>
  139. <?php
  140. $list = $wpdb->get_results("select referrer, SUM(if(status='C', 1, 0)) as confirmed, SUM(if(status='S', 1, 0)) as unconfirmed, SUM(if(status='B', 1, 0)) as bounced, SUM(if(status='U', 1, 0)) as unsubscribed from " . NEWSLETTER_USERS_TABLE . " group by referrer order by confirmed desc");
  141. ?>
  142. <table class="widefat" style="width: auto">
  143. <thead>
  144. <tr>
  145. <th><?php _e('Referrer', 'newsletter') ?></th>
  146. <th><?php _e('Confirmed', 'newsletter') ?></th>
  147. <th><?php _e('Not confirmed', 'newsletter') ?></th>
  148. <th><?php _e('Unsubscribed', 'newsletter') ?></th>
  149. <th><?php _e('Bounced', 'newsletter') ?></th>
  150. </tr>
  151. </thead>
  152. <tbody>
  153. <?php foreach ($list as $row) { ?>
  154. <tr>
  155. <td><?php echo empty($row->referrer) ? '[not set]' : esc_html($row->referrer) ?></td>
  156. <td><?php echo $row->confirmed; ?></td>
  157. <td><?php echo $row->unconfirmed; ?></td>
  158. <td><?php echo $row->unsubscribed; ?></td>
  159. <td><?php echo $row->bounced; ?></td>
  160. </tr>
  161. <?php } ?>
  162. </tbody>
  163. </table>
  164. </div>
  165. <div id="tabs-sources">
  166. <p>
  167. <?php $controls->panel_help('https://www.thenewsletterplugin.com/documentation/subscribers-statistics#source') ?>
  168. </p>
  169. <?php
  170. $list = $wpdb->get_results("select http_referer, SUM(if(status='C', 1, 0)) as confirmed, SUM(if(status='S', 1, 0)) as unconfirmed, SUM(if(status='B', 1, 0)) as bounced, SUM(if(status='U', 1, 0)) as unsubscribed from " . NEWSLETTER_USERS_TABLE . " group by http_referer order by count(*) desc limit 100");
  171. ?>
  172. <table class="widefat" style="width: auto">
  173. <thead>
  174. <tr>
  175. <th>URL</th>
  176. <th><?php _e('Confirmed', 'newsletter') ?></th>
  177. <th><?php _e('Not confirmed', 'newsletter') ?></th>
  178. <th><?php _e('Unsubscribed', 'newsletter') ?></th>
  179. <th><?php _e('Bounced', 'newsletter') ?></th>
  180. </tr>
  181. </thead>
  182. <tbody>
  183. <?php foreach ($list as $row) { ?>
  184. <tr>
  185. <td><?php echo empty($row->http_referer) ? '[not set]' : $controls->print_truncated($row->http_referer, 120) ?></td>
  186. <td><?php echo $row->confirmed; ?></td>
  187. <td><?php echo $row->unconfirmed; ?></td>
  188. <td><?php echo $row->unsubscribed; ?></td>
  189. <td><?php echo $row->bounced; ?></td>
  190. </tr>
  191. <?php } ?>
  192. </tbody>
  193. </table>
  194. </div>
  195. <div id="tabs-gender">
  196. <?php
  197. $male_count = $wpdb->get_row("select SUM(if(status='C', 1, 0)) as confirmed, SUM(if(status='S', 1, 0)) as unconfirmed, SUM(if(status='B', 1, 0)) as bounced, SUM(if(status='U', 1, 0)) as unsubscribed from " . NEWSLETTER_USERS_TABLE . " where sex='m'");
  198. $female_count = $wpdb->get_row("select SUM(if(status='C', 1, 0)) as confirmed, SUM(if(status='S', 1, 0)) as unconfirmed, SUM(if(status='B', 1, 0)) as bounced, SUM(if(status='U', 1, 0)) as unsubscribed from " . NEWSLETTER_USERS_TABLE . " where sex='f'");
  199. $none_count = $wpdb->get_row("select SUM(if(status='C', 1, 0)) as confirmed, SUM(if(status='S', 1, 0)) as unconfirmed, SUM(if(status='B', 1, 0)) as bounced, SUM(if(status='U', 1, 0)) as unsubscribed from " . NEWSLETTER_USERS_TABLE . " where sex='n'");
  200. ?>
  201. <table class="widefat">
  202. <thead>
  203. <tr>
  204. <th><?php _e('Gender', 'newsletter')?></th>
  205. <th><?php _e('Confirmed', 'newsletter') ?></th>
  206. <th><?php _e('Not confirmed', 'newsletter') ?></th>
  207. <th><?php _e('Unsubscribed', 'newsletter') ?></th>
  208. <th><?php _e('Bounced', 'newsletter') ?></th>
  209. </tr>
  210. </thead>
  211. <tbody>
  212. <tr>
  213. <td><?php _e('Female', 'newsletter')?></td>
  214. <td><?php echo $female_count->confirmed; ?></td>
  215. <td><?php echo $female_count->unconfirmed; ?></td>
  216. <td><?php echo $female_count->unsubscribed; ?></td>
  217. <td><?php echo $female_count->bounced; ?></td>
  218. </tr>
  219. <tr>
  220. <td><?php _e('Male', 'newsletter')?></td>
  221. <td><?php echo $male_count->confirmed; ?></td>
  222. <td><?php echo $male_count->unconfirmed; ?></td>
  223. <td><?php echo $male_count->unsubscribed; ?></td>
  224. <td><?php echo $male_count->bounced; ?></td>
  225. </tr>
  226. <tr>
  227. <td><?php _e('Not specified', 'newsletter')?></td>
  228. <td><?php echo $none_count->confirmed; ?></td>
  229. <td><?php echo $none_count->unconfirmed; ?></td>
  230. <td><?php echo $none_count->unsubscribed; ?></td>
  231. <td><?php echo $none_count->bounced; ?></td>
  232. </tr>
  233. </tbody>
  234. </table>
  235. </div>
  236. <div id="tabs-time">
  237. <?php
  238. if (!has_action('newsletter_users_statistics_time')) {
  239. include __DIR__ . '/statistics-time.php';
  240. } else {
  241. do_action('newsletter_users_statistics_time', $controls);
  242. }
  243. ?>
  244. </div>
  245. <?php
  246. if (isset($panels['user_statistics'])) {
  247. foreach ($panels['user_statistics'] as $panel) {
  248. call_user_func($panel['callback'], $id, $controls);
  249. }
  250. }
  251. ?>
  252. </div>
  253. </div>
  254. <?php include NEWSLETTER_DIR . '/tnp-footer.php'; ?>
  255. </div>