class-wc-admin-report.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. exit; // Exit if accessed directly
  4. }
  5. /**
  6. * Admin Report.
  7. *
  8. * Extended by reports to show charts and stats in admin.
  9. *
  10. * @author WooThemes
  11. * @category Admin
  12. * @package WooCommerce/Admin/Reports
  13. * @version 2.1.0
  14. */
  15. class WC_Admin_Report {
  16. /**
  17. * The chart interval.
  18. *
  19. * @var int
  20. */
  21. public $chart_interval;
  22. /**
  23. * Group by SQL query.
  24. *
  25. * @var string
  26. */
  27. public $group_by_query;
  28. /**
  29. * The bar width.
  30. *
  31. * @var int
  32. */
  33. public $barwidth;
  34. /**
  35. * Group chart item by day or month.
  36. *
  37. * @var string
  38. */
  39. public $chart_groupby;
  40. /**
  41. * The start date of the report.
  42. *
  43. * @var int timestamp
  44. */
  45. public $start_date;
  46. /**
  47. * The end date of the report.
  48. *
  49. * @var int timestamp
  50. */
  51. public $end_date;
  52. /**
  53. * Get report totals such as order totals and discount amounts.
  54. *
  55. * Data example:
  56. *
  57. * '_order_total' => array(
  58. * 'type' => 'meta',
  59. * 'function' => 'SUM',
  60. * 'name' => 'total_sales'
  61. * )
  62. *
  63. * @param array $args
  64. * @return mixed depending on query_type
  65. */
  66. public function get_order_report_data( $args = array() ) {
  67. global $wpdb;
  68. $default_args = array(
  69. 'data' => array(),
  70. 'where' => array(),
  71. 'where_meta' => array(),
  72. 'query_type' => 'get_row',
  73. 'group_by' => '',
  74. 'order_by' => '',
  75. 'limit' => '',
  76. 'filter_range' => false,
  77. 'nocache' => false,
  78. 'debug' => false,
  79. 'order_types' => wc_get_order_types( 'reports' ),
  80. 'order_status' => array( 'completed', 'processing', 'on-hold' ),
  81. 'parent_order_status' => false,
  82. );
  83. $args = apply_filters( 'woocommerce_reports_get_order_report_data_args', $args );
  84. $args = wp_parse_args( $args, $default_args );
  85. extract( $args );
  86. if ( empty( $data ) ) {
  87. return '';
  88. }
  89. $order_status = apply_filters( 'woocommerce_reports_order_statuses', $order_status );
  90. $query = array();
  91. $select = array();
  92. foreach ( $data as $raw_key => $value ) {
  93. $key = sanitize_key( $raw_key );
  94. $distinct = '';
  95. if ( isset( $value['distinct'] ) ) {
  96. $distinct = 'DISTINCT';
  97. }
  98. switch ( $value['type'] ) {
  99. case 'meta':
  100. $get_key = "meta_{$key}.meta_value";
  101. break;
  102. case 'parent_meta':
  103. $get_key = "parent_meta_{$key}.meta_value";
  104. break;
  105. case 'post_data':
  106. $get_key = "posts.{$key}";
  107. break;
  108. case 'order_item_meta':
  109. $get_key = "order_item_meta_{$key}.meta_value";
  110. break;
  111. case 'order_item':
  112. $get_key = "order_items.{$key}";
  113. break;
  114. default:
  115. continue;
  116. }
  117. if ( $value['function'] ) {
  118. $get = "{$value['function']}({$distinct} {$get_key})";
  119. } else {
  120. $get = "{$distinct} {$get_key}";
  121. }
  122. $select[] = "{$get} as {$value['name']}";
  123. }
  124. $query['select'] = 'SELECT ' . implode( ',', $select );
  125. $query['from'] = "FROM {$wpdb->posts} AS posts";
  126. // Joins
  127. $joins = array();
  128. foreach ( ( $data + $where ) as $raw_key => $value ) {
  129. $join_type = isset( $value['join_type'] ) ? $value['join_type'] : 'INNER';
  130. $type = isset( $value['type'] ) ? $value['type'] : false;
  131. $key = sanitize_key( $raw_key );
  132. switch ( $type ) {
  133. case 'meta':
  134. $joins[ "meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS meta_{$key} ON ( posts.ID = meta_{$key}.post_id AND meta_{$key}.meta_key = '{$raw_key}' )";
  135. break;
  136. case 'parent_meta':
  137. $joins[ "parent_meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS parent_meta_{$key} ON (posts.post_parent = parent_meta_{$key}.post_id) AND (parent_meta_{$key}.meta_key = '{$raw_key}')";
  138. break;
  139. case 'order_item_meta':
  140. $joins['order_items'] = "{$join_type} JOIN {$wpdb->prefix}woocommerce_order_items AS order_items ON (posts.ID = order_items.order_id)";
  141. if ( ! empty( $value['order_item_type'] ) ) {
  142. $joins['order_items'] .= " AND (order_items.order_item_type = '{$value['order_item_type']}')";
  143. }
  144. $joins[ "order_item_meta_{$key}" ] = "{$join_type} JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta_{$key} ON " .
  145. "(order_items.order_item_id = order_item_meta_{$key}.order_item_id) " .
  146. " AND (order_item_meta_{$key}.meta_key = '{$raw_key}')";
  147. break;
  148. case 'order_item':
  149. $joins['order_items'] = "{$join_type} JOIN {$wpdb->prefix}woocommerce_order_items AS order_items ON posts.ID = order_items.order_id";
  150. break;
  151. }
  152. }
  153. if ( ! empty( $where_meta ) ) {
  154. foreach ( $where_meta as $value ) {
  155. if ( ! is_array( $value ) ) {
  156. continue;
  157. }
  158. $join_type = isset( $value['join_type'] ) ? $value['join_type'] : 'INNER';
  159. $type = isset( $value['type'] ) ? $value['type'] : false;
  160. $key = sanitize_key( is_array( $value['meta_key'] ) ? $value['meta_key'][0] . '_array' : $value['meta_key'] );
  161. if ( 'order_item_meta' === $type ) {
  162. $joins['order_items'] = "{$join_type} JOIN {$wpdb->prefix}woocommerce_order_items AS order_items ON posts.ID = order_items.order_id";
  163. $joins[ "order_item_meta_{$key}" ] = "{$join_type} JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta_{$key} ON order_items.order_item_id = order_item_meta_{$key}.order_item_id";
  164. } else {
  165. // If we have a where clause for meta, join the postmeta table
  166. $joins[ "meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS meta_{$key} ON posts.ID = meta_{$key}.post_id";
  167. }
  168. }
  169. }
  170. if ( ! empty( $parent_order_status ) ) {
  171. $joins['parent'] = "LEFT JOIN {$wpdb->posts} AS parent ON posts.post_parent = parent.ID";
  172. }
  173. $query['join'] = implode( ' ', $joins );
  174. $query['where'] = "
  175. WHERE posts.post_type IN ( '" . implode( "','", $order_types ) . "' )
  176. ";
  177. if ( ! empty( $order_status ) ) {
  178. $query['where'] .= "
  179. AND posts.post_status IN ( 'wc-" . implode( "','wc-", $order_status ) . "')
  180. ";
  181. }
  182. if ( ! empty( $parent_order_status ) ) {
  183. if ( ! empty( $order_status ) ) {
  184. $query['where'] .= " AND ( parent.post_status IN ( 'wc-" . implode( "','wc-", $parent_order_status ) . "') OR parent.ID IS NULL ) ";
  185. } else {
  186. $query['where'] .= " AND parent.post_status IN ( 'wc-" . implode( "','wc-", $parent_order_status ) . "') ";
  187. }
  188. }
  189. if ( $filter_range ) {
  190. $query['where'] .= "
  191. AND posts.post_date >= '" . date( 'Y-m-d H:i:s', $this->start_date ) . "'
  192. AND posts.post_date < '" . date( 'Y-m-d H:i:s', strtotime( '+1 DAY', $this->end_date ) ) . "'
  193. ";
  194. }
  195. if ( ! empty( $where_meta ) ) {
  196. $relation = isset( $where_meta['relation'] ) ? $where_meta['relation'] : 'AND';
  197. $query['where'] .= ' AND (';
  198. foreach ( $where_meta as $index => $value ) {
  199. if ( ! is_array( $value ) ) {
  200. continue;
  201. }
  202. $key = sanitize_key( is_array( $value['meta_key'] ) ? $value['meta_key'][0] . '_array' : $value['meta_key'] );
  203. if ( strtolower( $value['operator'] ) == 'in' || strtolower( $value['operator'] ) == 'not in' ) {
  204. if ( is_array( $value['meta_value'] ) ) {
  205. $value['meta_value'] = implode( "','", $value['meta_value'] );
  206. }
  207. if ( ! empty( $value['meta_value'] ) ) {
  208. $where_value = "{$value['operator']} ('{$value['meta_value']}')";
  209. }
  210. } else {
  211. $where_value = "{$value['operator']} '{$value['meta_value']}'";
  212. }
  213. if ( ! empty( $where_value ) ) {
  214. if ( $index > 0 ) {
  215. $query['where'] .= ' ' . $relation;
  216. }
  217. if ( isset( $value['type'] ) && 'order_item_meta' === $value['type'] ) {
  218. if ( is_array( $value['meta_key'] ) ) {
  219. $query['where'] .= " ( order_item_meta_{$key}.meta_key IN ('" . implode( "','", $value['meta_key'] ) . "')";
  220. } else {
  221. $query['where'] .= " ( order_item_meta_{$key}.meta_key = '{$value['meta_key']}'";
  222. }
  223. $query['where'] .= " AND order_item_meta_{$key}.meta_value {$where_value} )";
  224. } else {
  225. if ( is_array( $value['meta_key'] ) ) {
  226. $query['where'] .= " ( meta_{$key}.meta_key IN ('" . implode( "','", $value['meta_key'] ) . "')";
  227. } else {
  228. $query['where'] .= " ( meta_{$key}.meta_key = '{$value['meta_key']}'";
  229. }
  230. $query['where'] .= " AND meta_{$key}.meta_value {$where_value} )";
  231. }
  232. }
  233. }
  234. $query['where'] .= ')';
  235. }
  236. if ( ! empty( $where ) ) {
  237. foreach ( $where as $value ) {
  238. if ( strtolower( $value['operator'] ) == 'in' || strtolower( $value['operator'] ) == 'not in' ) {
  239. if ( is_array( $value['value'] ) ) {
  240. $value['value'] = implode( "','", $value['value'] );
  241. }
  242. if ( ! empty( $value['value'] ) ) {
  243. $where_value = "{$value['operator']} ('{$value['value']}')";
  244. }
  245. } else {
  246. $where_value = "{$value['operator']} '{$value['value']}'";
  247. }
  248. if ( ! empty( $where_value ) ) {
  249. $query['where'] .= " AND {$value['key']} {$where_value}";
  250. }
  251. }
  252. }
  253. if ( $group_by ) {
  254. $query['group_by'] = "GROUP BY {$group_by}";
  255. }
  256. if ( $order_by ) {
  257. $query['order_by'] = "ORDER BY {$order_by}";
  258. }
  259. if ( $limit ) {
  260. $query['limit'] = "LIMIT {$limit}";
  261. }
  262. $query = apply_filters( 'woocommerce_reports_get_order_report_query', $query );
  263. $query = implode( ' ', $query );
  264. $query_hash = md5( $query_type . $query );
  265. $cached_results = get_transient( strtolower( get_class( $this ) ) );
  266. if ( $debug ) {
  267. echo '<pre>';
  268. wc_print_r( $query );
  269. echo '</pre>';
  270. }
  271. if ( $debug || $nocache || false === $cached_results || ! isset( $cached_results[ $query_hash ] ) ) {
  272. static $big_selects = false;
  273. // Enable big selects for reports, just once for this session
  274. if ( ! $big_selects ) {
  275. $wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' );
  276. $big_selects = true;
  277. }
  278. $cached_results[ $query_hash ] = apply_filters( 'woocommerce_reports_get_order_report_data', $wpdb->$query_type( $query ), $data );
  279. set_transient( strtolower( get_class( $this ) ), $cached_results, DAY_IN_SECONDS );
  280. }
  281. $result = $cached_results[ $query_hash ];
  282. return $result;
  283. }
  284. /**
  285. * Put data with post_date's into an array of times.
  286. *
  287. * @param array $data array of your data
  288. * @param string $date_key key for the 'date' field. e.g. 'post_date'
  289. * @param string $data_key key for the data you are charting
  290. * @param int $interval
  291. * @param string $start_date
  292. * @param string $group_by
  293. * @return array
  294. */
  295. public function prepare_chart_data( $data, $date_key, $data_key, $interval, $start_date, $group_by ) {
  296. $prepared_data = array();
  297. // Ensure all days (or months) have values in this range.
  298. if ( 'day' === $group_by ) {
  299. for ( $i = 0; $i <= $interval; $i ++ ) {
  300. $time = strtotime( date( 'Ymd', strtotime( "+{$i} DAY", $start_date ) ) ) . '000';
  301. if ( ! isset( $prepared_data[ $time ] ) ) {
  302. $prepared_data[ $time ] = array( esc_js( $time ), 0 );
  303. }
  304. }
  305. } else {
  306. $current_yearnum = date( 'Y', $start_date );
  307. $current_monthnum = date( 'm', $start_date );
  308. for ( $i = 0; $i <= $interval; $i ++ ) {
  309. $time = strtotime( $current_yearnum . str_pad( $current_monthnum, 2, '0', STR_PAD_LEFT ) . '01' ) . '000';
  310. if ( ! isset( $prepared_data[ $time ] ) ) {
  311. $prepared_data[ $time ] = array( esc_js( $time ), 0 );
  312. }
  313. $current_monthnum ++;
  314. if ( $current_monthnum > 12 ) {
  315. $current_monthnum = 1;
  316. $current_yearnum ++;
  317. }
  318. }
  319. }
  320. foreach ( $data as $d ) {
  321. switch ( $group_by ) {
  322. case 'day':
  323. $time = strtotime( date( 'Ymd', strtotime( $d->$date_key ) ) ) . '000';
  324. break;
  325. case 'month':
  326. default:
  327. $time = strtotime( date( 'Ym', strtotime( $d->$date_key ) ) . '01' ) . '000';
  328. break;
  329. }
  330. if ( ! isset( $prepared_data[ $time ] ) ) {
  331. continue;
  332. }
  333. if ( $data_key ) {
  334. $prepared_data[ $time ][1] += $d->$data_key;
  335. } else {
  336. $prepared_data[ $time ][1] ++;
  337. }
  338. }
  339. return $prepared_data;
  340. }
  341. /**
  342. * Prepares a sparkline to show sales in the last X days.
  343. *
  344. * @param int $id ID of the product to show. Blank to get all orders.
  345. * @param int $days Days of stats to get.
  346. * @param string $type Type of sparkline to get. Ignored if ID is not set.
  347. * @return string
  348. */
  349. public function sales_sparkline( $id = '', $days = 7, $type = 'sales' ) {
  350. if ( $id ) {
  351. $meta_key = ( 'sales' === $type ) ? '_line_total' : '_qty';
  352. $data = $this->get_order_report_data(
  353. array(
  354. 'data' => array(
  355. '_product_id' => array(
  356. 'type' => 'order_item_meta',
  357. 'order_item_type' => 'line_item',
  358. 'function' => '',
  359. 'name' => 'product_id',
  360. ),
  361. $meta_key => array(
  362. 'type' => 'order_item_meta',
  363. 'order_item_type' => 'line_item',
  364. 'function' => 'SUM',
  365. 'name' => 'sparkline_value',
  366. ),
  367. 'post_date' => array(
  368. 'type' => 'post_data',
  369. 'function' => '',
  370. 'name' => 'post_date',
  371. ),
  372. ),
  373. 'where' => array(
  374. array(
  375. 'key' => 'post_date',
  376. 'value' => date( 'Y-m-d', strtotime( 'midnight -' . ( $days - 1 ) . ' days', current_time( 'timestamp' ) ) ),
  377. 'operator' => '>',
  378. ),
  379. array(
  380. 'key' => 'order_item_meta__product_id.meta_value',
  381. 'value' => $id,
  382. 'operator' => '=',
  383. ),
  384. ),
  385. 'group_by' => 'YEAR(posts.post_date), MONTH(posts.post_date), DAY(posts.post_date)',
  386. 'query_type' => 'get_results',
  387. 'filter_range' => false,
  388. )
  389. );
  390. } else {
  391. $data = $this->get_order_report_data(
  392. array(
  393. 'data' => array(
  394. '_order_total' => array(
  395. 'type' => 'meta',
  396. 'function' => 'SUM',
  397. 'name' => 'sparkline_value',
  398. ),
  399. 'post_date' => array(
  400. 'type' => 'post_data',
  401. 'function' => '',
  402. 'name' => 'post_date',
  403. ),
  404. ),
  405. 'where' => array(
  406. array(
  407. 'key' => 'post_date',
  408. 'value' => date( 'Y-m-d', strtotime( 'midnight -' . ( $days - 1 ) . ' days', current_time( 'timestamp' ) ) ),
  409. 'operator' => '>',
  410. ),
  411. ),
  412. 'group_by' => 'YEAR(posts.post_date), MONTH(posts.post_date), DAY(posts.post_date)',
  413. 'query_type' => 'get_results',
  414. 'filter_range' => false,
  415. )
  416. );
  417. }
  418. $total = 0;
  419. foreach ( $data as $d ) {
  420. $total += $d->sparkline_value;
  421. }
  422. if ( 'sales' === $type ) {
  423. /* translators: 1: total income 2: days */
  424. $tooltip = sprintf( __( 'Sold %1$s worth in the last %2$d days', 'woocommerce' ), strip_tags( wc_price( $total ) ), $days );
  425. } else {
  426. /* translators: 1: total items sold 2: days */
  427. $tooltip = sprintf( _n( 'Sold 1 item in the last %2$d days', 'Sold %1$d items in the last %2$d days', $total, 'woocommerce' ), $total, $days );
  428. }
  429. $sparkline_data = array_values( $this->prepare_chart_data( $data, 'post_date', 'sparkline_value', $days - 1, strtotime( 'midnight -' . ( $days - 1 ) . ' days', current_time( 'timestamp' ) ), 'day' ) );
  430. return '<span class="wc_sparkline ' . ( ( 'sales' === $type ) ? 'lines' : 'bars' ) . ' tips" data-color="#777" data-tip="' . esc_attr( $tooltip ) . '" data-barwidth="' . 60 * 60 * 16 * 1000 . '" data-sparkline="' . esc_attr( json_encode( $sparkline_data ) ) . '"></span>';
  431. }
  432. /**
  433. * Get the current range and calculate the start and end dates.
  434. *
  435. * @param string $current_range
  436. */
  437. public function calculate_current_range( $current_range ) {
  438. switch ( $current_range ) {
  439. case 'custom':
  440. $this->start_date = max( strtotime( '-20 years' ), strtotime( sanitize_text_field( $_GET['start_date'] ) ) );
  441. if ( empty( $_GET['end_date'] ) ) {
  442. $this->end_date = strtotime( 'midnight', current_time( 'timestamp' ) );
  443. } else {
  444. $this->end_date = strtotime( 'midnight', strtotime( sanitize_text_field( $_GET['end_date'] ) ) );
  445. }
  446. $interval = 0;
  447. $min_date = $this->start_date;
  448. while ( ( $min_date = strtotime( '+1 MONTH', $min_date ) ) <= $this->end_date ) {
  449. $interval ++;
  450. }
  451. // 3 months max for day view
  452. if ( $interval > 3 ) {
  453. $this->chart_groupby = 'month';
  454. } else {
  455. $this->chart_groupby = 'day';
  456. }
  457. break;
  458. case 'year':
  459. $this->start_date = strtotime( date( 'Y-01-01', current_time( 'timestamp' ) ) );
  460. $this->end_date = strtotime( 'midnight', current_time( 'timestamp' ) );
  461. $this->chart_groupby = 'month';
  462. break;
  463. case 'last_month':
  464. $first_day_current_month = strtotime( date( 'Y-m-01', current_time( 'timestamp' ) ) );
  465. $this->start_date = strtotime( date( 'Y-m-01', strtotime( '-1 DAY', $first_day_current_month ) ) );
  466. $this->end_date = strtotime( date( 'Y-m-t', strtotime( '-1 DAY', $first_day_current_month ) ) );
  467. $this->chart_groupby = 'day';
  468. break;
  469. case 'month':
  470. $this->start_date = strtotime( date( 'Y-m-01', current_time( 'timestamp' ) ) );
  471. $this->end_date = strtotime( 'midnight', current_time( 'timestamp' ) );
  472. $this->chart_groupby = 'day';
  473. break;
  474. case '7day':
  475. $this->start_date = strtotime( '-6 days', strtotime( 'midnight', current_time( 'timestamp' ) ) );
  476. $this->end_date = strtotime( 'midnight', current_time( 'timestamp' ) );
  477. $this->chart_groupby = 'day';
  478. break;
  479. }
  480. // Group by
  481. switch ( $this->chart_groupby ) {
  482. case 'day':
  483. $this->group_by_query = 'YEAR(posts.post_date), MONTH(posts.post_date), DAY(posts.post_date)';
  484. $this->chart_interval = absint( ceil( max( 0, ( $this->end_date - $this->start_date ) / ( 60 * 60 * 24 ) ) ) );
  485. $this->barwidth = 60 * 60 * 24 * 1000;
  486. break;
  487. case 'month':
  488. $this->group_by_query = 'YEAR(posts.post_date), MONTH(posts.post_date)';
  489. $this->chart_interval = 0;
  490. $min_date = strtotime( date( 'Y-m-01', $this->start_date ) );
  491. while ( ( $min_date = strtotime( '+1 MONTH', $min_date ) ) <= $this->end_date ) {
  492. $this->chart_interval ++;
  493. }
  494. $this->barwidth = 60 * 60 * 24 * 7 * 4 * 1000;
  495. break;
  496. }
  497. }
  498. /**
  499. * Return currency tooltip JS based on WooCommerce currency position settings.
  500. *
  501. * @return string
  502. */
  503. public function get_currency_tooltip() {
  504. switch ( get_option( 'woocommerce_currency_pos' ) ) {
  505. case 'right':
  506. $currency_tooltip = 'append_tooltip: "' . get_woocommerce_currency_symbol() . '"';
  507. break;
  508. case 'right_space':
  509. $currency_tooltip = 'append_tooltip: "&nbsp;' . get_woocommerce_currency_symbol() . '"';
  510. break;
  511. case 'left':
  512. $currency_tooltip = 'prepend_tooltip: "' . get_woocommerce_currency_symbol() . '"';
  513. break;
  514. case 'left_space':
  515. default:
  516. $currency_tooltip = 'prepend_tooltip: "' . get_woocommerce_currency_symbol() . '&nbsp;"';
  517. break;
  518. }
  519. return $currency_tooltip;
  520. }
  521. /**
  522. * Get the main chart.
  523. */
  524. public function get_main_chart() {}
  525. /**
  526. * Get the legend for the main chart sidebar.
  527. *
  528. * @return array
  529. */
  530. public function get_chart_legend() {
  531. return array();
  532. }
  533. /**
  534. * Get chart widgets.
  535. *
  536. * @return array
  537. */
  538. public function get_chart_widgets() {
  539. return array();
  540. }
  541. /**
  542. * Get an export link if needed.
  543. */
  544. public function get_export_button() {}
  545. /**
  546. * Output the report.
  547. */
  548. public function output_report() {}
  549. /**
  550. * Check nonce for current range.
  551. *
  552. * @since 3.0.4
  553. * @param string $current_range Current range.
  554. */
  555. public function check_current_range_nonce( $current_range ) {
  556. if ( 'custom' !== $current_range ) {
  557. return;
  558. }
  559. if ( ! isset( $_GET['wc_reports_nonce'] ) || ! wp_verify_nonce( sanitize_key( $_GET['wc_reports_nonce'] ), 'custom_range' ) ) { // WPCS: input var ok, CSRF ok.
  560. wp_die(
  561. /* translators: %1$s: open link, %2$s: close link */
  562. sprintf( esc_html__( 'This report link has expired. %1$sClick here to view the filtered report%2$s.', 'woocommerce' ), '<a href="' . esc_url( wp_nonce_url( esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 'custom_range', 'wc_reports_nonce' ) ) . '">', '</a>' ), // @codingStandardsIgnoreLine.
  563. esc_attr__( 'Confirm navigation', 'woocommerce' )
  564. );
  565. exit;
  566. }
  567. }
  568. }