| @@ -5,9 +5,9 @@ | ||
| 5 | 5 | * A front-facing JSON/XML API that makes it possible to query donation data. |
| 6 | 6 | * |
| 7 | 7 | * @package Give |
| 8 | 8 | * @subpackage Classes/API |
| 9 | - * @copyright Copyright (c) 2016, WordImpress | |
| 9 | + * @copyright Copyright (c) 2016, GiveWP | |
| 10 | 10 | * @license https://opensource.org/licenses/gpl-license GNU Public License |
| 11 | 11 | * @since 1.1 |
| 12 | 12 | */ |
| 13 | 13 | |
| @@ -342,9 +342,9 @@ | ||
| 342 | 342 | return false; |
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | // Retrieve the user by public API key and ensure they exist |
| 346 | - if ( ! ( $user = $this->get_user( $wp_query->query_vars['key'] ) ) ) { | |
| 346 | + if ( ! preg_match( '/^[a-f0-9]{32}$/i', $wp_query->query_vars['key'] ) || ! ( $user = $this->get_user( $wp_query->query_vars['key'] ) ) ) { | |
| 347 | 347 | |
| 348 | 348 | $this->invalid_key(); |
| 349 | 349 | |
| 350 | 350 | return false; |
| @@ -349,13 +349,17 @@ | ||
| 349 | 349 | |
| 350 | 350 | return false; |
| 351 | 351 | |
| 352 | 352 | } else { |
| 353 | - | |
| 354 | 353 | $token = urldecode( $wp_query->query_vars['token'] ); |
| 355 | 354 | $secret = $this->get_user_secret_key( $user ); |
| 356 | 355 | $public = urldecode( $wp_query->query_vars['key'] ); |
| 357 | 356 | |
| 357 | + // Verify that if user has secret key or not | |
| 358 | + if ( ! $secret ) { | |
| 359 | + $this->invalid_auth(); | |
| 360 | + } | |
| 361 | + | |
| 358 | 362 | if ( hash_equals( md5( $secret . $public ), $token ) ) { |
| 359 | 363 | $this->is_valid_request = true; |
| 360 | 364 | } else { |
| 361 | 365 | $this->invalid_auth(); |
| @@ -361,9 +365,8 @@ | ||
| 361 | 365 | $this->invalid_auth(); |
| 362 | 366 | |
| 363 | 367 | return false; |
| 364 | 368 | } |
| 365 | - | |
| 366 | 369 | } |
| 367 | 370 | } elseif ( ! empty( $wp_query->query_vars['give-api'] ) && $wp_query->query_vars['give-api'] === 'forms' ) { |
| 368 | 371 | $this->is_valid_request = true; |
| 369 | 372 | $wp_query->set( 'key', 'public' ); |
| @@ -395,9 +398,9 @@ | ||
| 395 | 398 | |
| 396 | 399 | $user = Give_Cache::get( md5( 'give_api_user_' . $key ), true ); |
| 397 | 400 | |
| 398 | 401 | if ( false === $user ) { |
| 399 | - $user = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s LIMIT 1", $key ) ); | |
| 402 | + $user = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s AND meta_value=%s LIMIT 1", $key, 'give_user_public_key' ) ); | |
| 400 | 403 | Give_Cache::set( md5( 'give_api_user_' . $key ), $user, DAY_IN_SECONDS, true ); |
| 401 | 404 | } |
| 402 | 405 | |
| 403 | 406 | if ( $user != null ) { |
| @@ -563,27 +566,27 @@ | ||
| 563 | 566 | define( 'GIVE_DOING_API', true ); |
| 564 | 567 | } |
| 565 | 568 | |
| 566 | 569 | $data = array(); |
| 567 | - $this->routes = new $this->versions[$this->get_queried_version()]; | |
| 570 | + $this->routes = new $this->versions[ $this->get_queried_version() ]; | |
| 568 | 571 | $this->routes->validate_request(); |
| 569 | 572 | |
| 570 | 573 | switch ( $this->endpoint ) : |
| 571 | 574 | |
| 572 | - case 'stats' : | |
| 575 | + case 'stats': | |
| 576 | + $data = $this->routes->get_stats( | |
| 577 | + array( | |
| 578 | + 'type' => isset( $wp_query->query_vars['type'] ) ? $wp_query->query_vars['type'] : null, | |
| 579 | + 'form' => isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null, | |
| 580 | + 'date' => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null, | |
| 581 | + 'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null, | |
| 582 | + 'enddate' => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null, | |
| 583 | + ) | |
| 584 | + ); | |
| 573 | 585 | |
| 574 | - $data = $this->routes->get_stats( array( | |
| 575 | - 'type' => isset( $wp_query->query_vars['type'] ) ? $wp_query->query_vars['type'] : null, | |
| 576 | - 'form' => isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null, | |
| 577 | - 'date' => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null, | |
| 578 | - 'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null, | |
| 579 | - 'enddate' => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null, | |
| 580 | - ) ); | |
| 581 | - | |
| 582 | 586 | break; |
| 583 | 587 | |
| 584 | - case 'forms' : | |
| 585 | - | |
| 588 | + case 'forms': | |
| 586 | 589 | $form = isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null; |
| 587 | 590 | |
| 588 | 591 | $data = $this->routes->get_forms( $form ); |
| 589 | 592 | |
| @@ -588,10 +591,9 @@ | ||
| 588 | 591 | $data = $this->routes->get_forms( $form ); |
| 589 | 592 | |
| 590 | 593 | break; |
| 591 | 594 | |
| 592 | - case 'donors' : | |
| 593 | - | |
| 595 | + case 'donors': | |
| 594 | 596 | $donor = isset( $wp_query->query_vars['donor'] ) ? $wp_query->query_vars['donor'] : null; |
| 595 | 597 | |
| 596 | 598 | $data = $this->routes->get_donors( $donor ); |
| 597 | 599 | |
| @@ -596,10 +598,9 @@ | ||
| 596 | 598 | $data = $this->routes->get_donors( $donor ); |
| 597 | 599 | |
| 598 | 600 | break; |
| 599 | 601 | |
| 600 | - case 'donations' : | |
| 601 | - | |
| 602 | + case 'donations': | |
| 602 | 603 | /** |
| 603 | 604 | * Call to get recent donations |
| 604 | 605 | * |
| 605 | 606 | * @params text date | today, yesterday or range |
| @@ -605,14 +606,16 @@ | ||
| 605 | 606 | * @params text date | today, yesterday or range |
| 606 | 607 | * @params date startdate | required when date = range and format to be YYYYMMDD (i.e. 20170524) |
| 607 | 608 | * @params date enddate | required when date = range and format to be YYYYMMDD (i.e. 20170524) |
| 608 | 609 | */ |
| 609 | - $data = $this->routes->get_recent_donations( array( | |
| 610 | - 'id' => isset( $wp_query->query_vars['id'] ) ? $wp_query->query_vars['id'] : null, | |
| 611 | - 'date' => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null, | |
| 612 | - 'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null, | |
| 613 | - 'enddate' => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null, | |
| 614 | - ) ); | |
| 610 | + $data = $this->routes->get_recent_donations( | |
| 611 | + array( | |
| 612 | + 'id' => isset( $wp_query->query_vars['id'] ) ? $wp_query->query_vars['id'] : null, | |
| 613 | + 'date' => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null, | |
| 614 | + 'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null, | |
| 615 | + 'enddate' => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null, | |
| 616 | + ) | |
| 617 | + ); | |
| 615 | 618 | |
| 616 | 619 | break; |
| 617 | 620 | |
| 618 | 621 | endswitch; |
| @@ -654,14 +657,17 @@ | ||
| 654 | 657 | |
| 655 | 658 | global $wp_query; |
| 656 | 659 | |
| 657 | 660 | // Whitelist our query options |
| 658 | - $accepted = apply_filters( 'give_api_valid_query_modes', array( | |
| 659 | - 'stats', | |
| 660 | - 'forms', | |
| 661 | - 'donors', | |
| 662 | - 'donations', | |
| 663 | - ) ); | |
| 661 | + $accepted = apply_filters( | |
| 662 | + 'give_api_valid_query_modes', | |
| 663 | + array( | |
| 664 | + 'stats', | |
| 665 | + 'forms', | |
| 666 | + 'donors', | |
| 667 | + 'donations', | |
| 668 | + ) | |
| 669 | + ); | |
| 664 | 670 | |
| 665 | 671 | $query = isset( $wp_query->query_vars['give-api'] ) ? $wp_query->query_vars['give-api'] : null; |
| 666 | 672 | $query = str_replace( $this->queried_version . '/', '', $query ); |
| 667 | 673 | |
| @@ -751,9 +757,9 @@ | ||
| 751 | 757 | } else { |
| 752 | 758 | // Modify dates based on predefined ranges |
| 753 | 759 | switch ( $args['date'] ) : |
| 754 | 760 | |
| 755 | - case 'this_month' : | |
| 761 | + case 'this_month': | |
| 756 | 762 | $dates['day'] = null; |
| 757 | 763 | $dates['m_start'] = date( 'n', $current_time ); |
| 758 | 764 | $dates['m_end'] = date( 'n', $current_time ); |
| 759 | 765 | $dates['year'] = date( 'Y', $current_time ); |
| @@ -758,9 +764,9 @@ | ||
| 758 | 764 | $dates['m_end'] = date( 'n', $current_time ); |
| 759 | 765 | $dates['year'] = date( 'Y', $current_time ); |
| 760 | 766 | break; |
| 761 | 767 | |
| 762 | - case 'last_month' : | |
| 768 | + case 'last_month': | |
| 763 | 769 | $dates['day'] = null; |
| 764 | 770 | $dates['m_start'] = date( 'n', $current_time ) == 1 ? 12 : date( 'n', $current_time ) - 1; |
| 765 | 771 | $dates['m_end'] = $dates['m_start']; |
| 766 | 772 | $dates['year'] = date( 'n', $current_time ) == 1 ? date( 'Y', $current_time ) - 1 : date( 'Y', $current_time ); |
| @@ -765,9 +771,9 @@ | ||
| 765 | 771 | $dates['m_end'] = $dates['m_start']; |
| 766 | 772 | $dates['year'] = date( 'n', $current_time ) == 1 ? date( 'Y', $current_time ) - 1 : date( 'Y', $current_time ); |
| 767 | 773 | break; |
| 768 | 774 | |
| 769 | - case 'today' : | |
| 775 | + case 'today': | |
| 770 | 776 | $dates['day'] = date( 'd', $current_time ); |
| 771 | 777 | $dates['m_start'] = date( 'n', $current_time ); |
| 772 | 778 | $dates['m_end'] = date( 'n', $current_time ); |
| 773 | 779 | $dates['year'] = date( 'Y', $current_time ); |
| @@ -772,10 +778,9 @@ | ||
| 772 | 778 | $dates['m_end'] = date( 'n', $current_time ); |
| 773 | 779 | $dates['year'] = date( 'Y', $current_time ); |
| 774 | 780 | break; |
| 775 | 781 | |
| 776 | - case 'yesterday' : | |
| 777 | - | |
| 782 | + case 'yesterday': | |
| 778 | 783 | $year = date( 'Y', $current_time ); |
| 779 | 784 | $month = date( 'n', $current_time ); |
| 780 | 785 | $day = date( 'd', $current_time ); |
| 781 | 786 | |
| @@ -780,9 +785,9 @@ | ||
| 780 | 785 | $day = date( 'd', $current_time ); |
| 781 | 786 | |
| 782 | 787 | if ( $month == 1 && $day == 1 ) { |
| 783 | 788 | |
| 784 | - $year -= 1; | |
| 789 | + $year -= 1; | |
| 785 | 790 | $month = 12; |
| 786 | 791 | $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
| 787 | 792 | |
| 788 | 793 | } elseif ( $month > 1 && $day == 1 ) { |
| @@ -787,9 +792,9 @@ | ||
| 787 | 792 | |
| 788 | 793 | } elseif ( $month > 1 && $day == 1 ) { |
| 789 | 794 | |
| 790 | 795 | $month -= 1; |
| 791 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); | |
| 796 | + $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); | |
| 792 | 797 | |
| 793 | 798 | } else { |
| 794 | 799 | |
| 795 | 800 | $day -= 1; |
| @@ -802,9 +807,9 @@ | ||
| 802 | 807 | $dates['year'] = $year; |
| 803 | 808 | |
| 804 | 809 | break; |
| 805 | 810 | |
| 806 | - case 'this_quarter' : | |
| 811 | + case 'this_quarter': | |
| 807 | 812 | $month_now = date( 'n', $current_time ); |
| 808 | 813 | |
| 809 | 814 | $dates['day'] = null; |
| 810 | 815 | |
| @@ -834,9 +839,9 @@ | ||
| 834 | 839 | |
| 835 | 840 | } |
| 836 | 841 | break; |
| 837 | 842 | |
| 838 | - case 'last_quarter' : | |
| 843 | + case 'last_quarter': | |
| 839 | 844 | $month_now = date( 'n', $current_time ); |
| 840 | 845 | |
| 841 | 846 | $dates['day'] = null; |
| 842 | 847 | |
| @@ -866,9 +871,9 @@ | ||
| 866 | 871 | |
| 867 | 872 | } |
| 868 | 873 | break; |
| 869 | 874 | |
| 870 | - case 'this_year' : | |
| 875 | + case 'this_year': | |
| 871 | 876 | $dates['day'] = null; |
| 872 | 877 | $dates['m_start'] = null; |
| 873 | 878 | $dates['m_end'] = null; |
| 874 | 879 | $dates['year'] = date( 'Y', $current_time ); |
| @@ -873,9 +878,9 @@ | ||
| 873 | 878 | $dates['m_end'] = null; |
| 874 | 879 | $dates['year'] = date( 'Y', $current_time ); |
| 875 | 880 | break; |
| 876 | 881 | |
| 877 | - case 'last_year' : | |
| 882 | + case 'last_year': | |
| 878 | 883 | $dates['day'] = null; |
| 879 | 884 | $dates['m_start'] = null; |
| 880 | 885 | $dates['m_end'] = null; |
| 881 | 886 | $dates['year'] = date( 'Y', $current_time ) - 1; |
| @@ -922,13 +927,15 @@ | ||
| 922 | 927 | } else { |
| 923 | 928 | $field = 'email'; |
| 924 | 929 | } |
| 925 | 930 | |
| 926 | - $donor_query = Give()->donors->get_donors( array( | |
| 927 | - 'number' => $per_page, | |
| 928 | - 'offset' => $offset, | |
| 929 | - $field => $donor, | |
| 930 | - ) ); | |
| 931 | + $donor_query = Give()->donors->get_donors( | |
| 932 | + array( | |
| 933 | + 'number' => $per_page, | |
| 934 | + 'offset' => $offset, | |
| 935 | + $field => $donor, | |
| 936 | + ) | |
| 937 | + ); | |
| 931 | 938 | $donor_count = 0; |
| 932 | 939 | |
| 933 | 940 | if ( $donor_query ) { |
| 934 | 941 | |
| @@ -1018,14 +1025,16 @@ | ||
| 1018 | 1025 | |
| 1019 | 1026 | if ( $form == null ) { |
| 1020 | 1027 | $forms['forms'] = array(); |
| 1021 | 1028 | |
| 1022 | - $form_list = get_posts( array( | |
| 1023 | - 'post_type' => 'give_forms', | |
| 1024 | - 'posts_per_page' => $this->per_page(), | |
| 1025 | - 'suppress_filters' => true, | |
| 1026 | - 'paged' => $this->get_paged(), | |
| 1027 | - ) ); | |
| 1029 | + $form_list = get_posts( | |
| 1030 | + array( | |
| 1031 | + 'post_type' => 'give_forms', | |
| 1032 | + 'posts_per_page' => $this->per_page(), | |
| 1033 | + 'suppress_filters' => true, | |
| 1034 | + 'paged' => $this->get_paged(), | |
| 1035 | + ) | |
| 1036 | + ); | |
| 1028 | 1037 | |
| 1029 | 1038 | if ( $form_list ) { |
| 1030 | 1039 | $i = 0; |
| 1031 | 1040 | foreach ( $form_list as $form_info ) { |
| @@ -1040,9 +1049,11 @@ | ||
| 1040 | 1049 | $forms['forms'][0] = $this->get_form_data( $form_info ); |
| 1041 | 1050 | |
| 1042 | 1051 | } else { |
| 1043 | 1052 | $error['error'] = sprintf( /* translators: %s: form */ |
| 1044 | - __( 'Form %s not found.', 'give' ), $form ); | |
| 1053 | + __( 'Form %s not found.', 'give' ), | |
| 1054 | + $form | |
| 1055 | + ); | |
| 1045 | 1056 | |
| 1046 | 1057 | return $error; |
| 1047 | 1058 | } |
| 1048 | 1059 | } |
| @@ -1060,9 +1071,10 @@ | ||
| 1060 | 1071 | * @return array Array of post data to return back in the API. |
| 1061 | 1072 | */ |
| 1062 | 1073 | private function get_form_data( $form_info ) { |
| 1063 | 1074 | |
| 1064 | - $form = array(); | |
| 1075 | + $form = array(); | |
| 1076 | + $currency = give_get_option( 'currency' ); | |
| 1065 | 1077 | |
| 1066 | 1078 | $form['info']['id'] = $form_info->ID; |
| 1067 | 1079 | $form['info']['slug'] = $form_info->post_name; |
| 1068 | 1080 | $form['info']['title'] = $form_info->post_title; |
| @@ -1086,17 +1098,32 @@ | ||
| 1086 | 1098 | $goal_amount = give_get_meta( $form_info->ID, '_give_set_goal', true ); |
| 1087 | 1099 | if ( give_is_setting_enabled( $goal_option ) && $goal_amount ) { |
| 1088 | 1100 | $total_income = give_get_form_earnings_stats( $form_info->ID ); |
| 1089 | 1101 | $goal_percentage_completed = ( $total_income < $goal_amount ) ? round( ( $total_income / $goal_amount ) * 100, 2 ) : 100; |
| 1090 | - $form['goal']['amount'] = isset( $goal_amount ) ? $goal_amount : ''; | |
| 1102 | + $form['goal']['amount'] = isset( $goal_amount ) ? give_format_decimal( | |
| 1103 | + array( | |
| 1104 | + 'amount' => $goal_amount, | |
| 1105 | + 'currency' => $currency, | |
| 1106 | + ) | |
| 1107 | + ) : ''; | |
| 1091 | 1108 | $form['goal']['percentage_completed'] = isset( $goal_percentage_completed ) ? $goal_percentage_completed : ''; |
| 1092 | 1109 | } |
| 1093 | 1110 | |
| 1094 | 1111 | if ( user_can( $this->user_id, 'view_give_reports' ) || $this->override ) { |
| 1095 | 1112 | $form['stats']['total']['donations'] = give_get_form_sales_stats( $form_info->ID ); |
| 1096 | - $form['stats']['total']['earnings'] = give_get_form_earnings_stats( $form_info->ID ); | |
| 1113 | + $form['stats']['total']['earnings'] = give_format_decimal( | |
| 1114 | + array( | |
| 1115 | + 'amount' => give_get_form_earnings_stats( $form_info->ID ), | |
| 1116 | + 'currency' => $currency, | |
| 1117 | + ) | |
| 1118 | + ); | |
| 1097 | 1119 | $form['stats']['monthly_average']['donations'] = give_get_average_monthly_form_sales( $form_info->ID ); |
| 1098 | - $form['stats']['monthly_average']['earnings'] = give_get_average_monthly_form_earnings( $form_info->ID ); | |
| 1120 | + $form['stats']['monthly_average']['earnings'] = give_format_decimal( | |
| 1121 | + array( | |
| 1122 | + 'amount' => give_get_average_monthly_form_earnings( $form_info->ID ), | |
| 1123 | + 'currency' => $currency, | |
| 1124 | + ) | |
| 1125 | + ); | |
| 1099 | 1126 | } |
| 1100 | 1127 | |
| 1101 | 1128 | $counter = 0; |
| 1102 | 1129 | if ( give_has_variable_prices( $form_info->ID ) ) { |
| @@ -1103,13 +1130,23 @@ | ||
| 1103 | 1130 | foreach ( give_get_variable_prices( $form_info->ID ) as $price ) { |
| 1104 | 1131 | $counter ++; |
| 1105 | 1132 | // multi-level item |
| 1106 | 1133 | $level = isset( $price['_give_text'] ) ? $price['_give_text'] : 'level-' . $counter; |
| 1107 | - $form['pricing'][ sanitize_key( $level ) ] = $price['_give_amount']; | |
| 1134 | + $form['pricing'][ sanitize_key( $level ) ] = give_format_decimal( | |
| 1135 | + array( | |
| 1136 | + 'amount' => $price['_give_amount'], | |
| 1137 | + 'currency' => $currency, | |
| 1138 | + ) | |
| 1139 | + ); | |
| 1108 | 1140 | |
| 1109 | 1141 | } |
| 1110 | 1142 | } else { |
| 1111 | - $form['pricing']['amount'] = give_get_form_price( $form_info->ID ); | |
| 1143 | + $form['pricing']['amount'] = give_format_decimal( | |
| 1144 | + array( | |
| 1145 | + 'amount' => give_get_form_price( $form_info->ID ), | |
| 1146 | + 'currency' => $currency, | |
| 1147 | + ) | |
| 1148 | + ); | |
| 1112 | 1149 | } |
| 1113 | 1150 | |
| 1114 | 1151 | if ( user_can( $this->user_id, 'view_give_sensitive_data' ) || $this->override ) { |
| 1115 | 1152 | |
| @@ -1149,8 +1186,9 @@ | ||
| 1149 | 1186 | $args = wp_parse_args( $args, $defaults ); |
| 1150 | 1187 | |
| 1151 | 1188 | $dates = $this->get_dates( $args ); |
| 1152 | 1189 | |
| 1190 | + $currency = give_get_option( 'currency' ); | |
| 1153 | 1191 | $stats = array(); |
| 1154 | 1192 | $earnings = array( |
| 1155 | 1193 | 'earnings' => array(), |
| 1156 | 1194 | ); |
| @@ -1249,12 +1287,14 @@ | ||
| 1249 | 1287 | $donations['donations'][ $args['date'] ] = give_get_sales_by_date( $dates['day'], $dates['m_start'], $dates['year'] ); |
| 1250 | 1288 | } |
| 1251 | 1289 | }// End if(). |
| 1252 | 1290 | } elseif ( $args['form'] == 'all' ) { |
| 1253 | - $forms = get_posts( array( | |
| 1254 | - 'post_type' => 'give_forms', | |
| 1255 | - 'nopaging' => true, | |
| 1256 | - ) ); | |
| 1291 | + $forms = get_posts( | |
| 1292 | + array( | |
| 1293 | + 'post_type' => 'give_forms', | |
| 1294 | + 'nopaging' => true, | |
| 1295 | + ) | |
| 1296 | + ); | |
| 1257 | 1297 | $i = 0; |
| 1258 | 1298 | foreach ( $forms as $form_info ) { |
| 1259 | 1299 | $donations['donations'][ $i ] = array( |
| 1260 | 1300 | $form_info->post_name => $this->stats->get_sales( |
| @@ -1284,9 +1324,11 @@ | ||
| 1284 | 1324 | ), |
| 1285 | 1325 | ); |
| 1286 | 1326 | } else { |
| 1287 | 1327 | $error['error'] = sprintf( /* translators: %s: form */ |
| 1288 | - __( 'Form %s not found.', 'give' ), $args['form'] ); | |
| 1328 | + __( 'Form %s not found.', 'give' ), | |
| 1329 | + $args['form'] | |
| 1330 | + ); | |
| 1289 | 1331 | } |
| 1290 | 1332 | }// End if(). |
| 1291 | 1333 | |
| 1292 | 1334 | if ( ! empty( $error ) ) { |
| @@ -1354,9 +1396,15 @@ | ||
| 1354 | 1396 | $date_key = date( 'Ymd', strtotime( $y . '/' . $i . '/' . $d ) ); |
| 1355 | 1397 | if ( ! isset( $earnings['earnings'][ $date_key ] ) ) { |
| 1356 | 1398 | $earnings['earnings'][ $date_key ] = 0; |
| 1357 | 1399 | } |
| 1358 | - $earnings['earnings'][ $date_key ] += $earnings_stat; | |
| 1400 | + | |
| 1401 | + $earnings['earnings'][ $date_key ] += give_format_decimal( | |
| 1402 | + array( | |
| 1403 | + 'amount' => $earnings_stat, | |
| 1404 | + 'currency' => $currency, | |
| 1405 | + ) | |
| 1406 | + ); | |
| 1359 | 1407 | $total += $earnings_stat; |
| 1360 | 1408 | $d ++; |
| 1361 | 1409 | endwhile; |
| 1362 | 1410 | |
| @@ -1365,9 +1413,14 @@ | ||
| 1365 | 1413 | |
| 1366 | 1414 | $y ++; |
| 1367 | 1415 | endwhile; |
| 1368 | 1416 | |
| 1369 | - $earnings['totals'] = $total; | |
| 1417 | + $earnings['totals'] = give_format_decimal( | |
| 1418 | + array( | |
| 1419 | + 'amount' => $total, | |
| 1420 | + 'currency' => $currency, | |
| 1421 | + ) | |
| 1422 | + ); | |
| 1370 | 1423 | } else { |
| 1371 | 1424 | if ( $args['date'] == 'this_quarter' || $args['date'] == 'last_quarter' ) { |
| 1372 | 1425 | $earnings_count = (float) 0.00; |
| 1373 | 1426 | |
| @@ -1378,23 +1431,40 @@ | ||
| 1378 | 1431 | $earnings_count += give_get_earnings_by_date( null, $month, $dates['year'] ); |
| 1379 | 1432 | $month ++; |
| 1380 | 1433 | endwhile; |
| 1381 | 1434 | |
| 1382 | - $earnings['earnings'][ $args['date'] ] = $earnings_count; | |
| 1435 | + $earnings['earnings'][ $args['date'] ] = give_format_decimal( | |
| 1436 | + array( | |
| 1437 | + 'amount' => $earnings_count, | |
| 1438 | + 'currency' => $currency, | |
| 1439 | + ) | |
| 1440 | + ); | |
| 1383 | 1441 | } else { |
| 1384 | - $earnings['earnings'][ $args['date'] ] = give_get_earnings_by_date( $dates['day'], $dates['m_start'], $dates['year'] ); | |
| 1442 | + $earnings['earnings'][ $args['date'] ] = give_format_decimal( | |
| 1443 | + array( | |
| 1444 | + 'amount' => give_get_earnings_by_date( $dates['day'], $dates['m_start'], $dates['year'] ), | |
| 1445 | + 'currency' => $currency, | |
| 1446 | + ) | |
| 1447 | + ); | |
| 1385 | 1448 | } |
| 1386 | 1449 | }// End if(). |
| 1387 | 1450 | } elseif ( $args['form'] == 'all' ) { |
| 1388 | - $forms = get_posts( array( | |
| 1389 | - 'post_type' => 'give_forms', | |
| 1390 | - 'nopaging' => true, | |
| 1391 | - ) ); | |
| 1451 | + $forms = get_posts( | |
| 1452 | + array( | |
| 1453 | + 'post_type' => 'give_forms', | |
| 1454 | + 'nopaging' => true, | |
| 1455 | + ) | |
| 1456 | + ); | |
| 1392 | 1457 | |
| 1393 | 1458 | $i = 0; |
| 1394 | 1459 | foreach ( $forms as $form_info ) { |
| 1395 | 1460 | $earnings['earnings'][ $i ] = array( |
| 1396 | - $form_info->post_name => give_get_form_earnings_stats( $form_info->ID ), | |
| 1461 | + $form_info->post_name => give_format_decimal( | |
| 1462 | + array( | |
| 1463 | + 'amount' => give_get_form_earnings_stats( $form_info->ID ), | |
| 1464 | + 'currency' => $currency, | |
| 1465 | + ) | |
| 1466 | + ), | |
| 1397 | 1467 | ); |
| 1398 | 1468 | $i ++; |
| 1399 | 1469 | } |
| 1400 | 1470 | } else { |
| @@ -1400,21 +1470,28 @@ | ||
| 1400 | 1470 | } else { |
| 1401 | 1471 | if ( get_post_type( $args['form'] ) == 'give_forms' ) { |
| 1402 | 1472 | $form_info = get_post( $args['form'] ); |
| 1403 | 1473 | $earnings['earnings'][0] = array( |
| 1404 | - $form_info->post_name => $this->stats->get_earnings( | |
| 1405 | - $args['form'], | |
| 1406 | - is_numeric( $args['startdate'] ) | |
| 1474 | + $form_info->post_name => give_format_decimal( | |
| 1475 | + array( | |
| 1476 | + 'amount' => $this->stats->get_earnings( | |
| 1477 | + $args['form'], | |
| 1478 | + is_numeric( $args['startdate'] ) | |
| 1407 | 1479 | ? strtotime( $args['startdate'] ) |
| 1408 | 1480 | : $args['startdate'], |
| 1409 | - is_numeric( $args['enddate'] ) | |
| 1481 | + is_numeric( $args['enddate'] ) | |
| 1410 | 1482 | ? strtotime( $args['enddate'] ) |
| 1411 | 1483 | : $args['enddate'] |
| 1484 | + ), | |
| 1485 | + 'currency' => $currency, | |
| 1486 | + ) | |
| 1412 | 1487 | ), |
| 1413 | 1488 | ); |
| 1414 | 1489 | } else { |
| 1415 | 1490 | $error['error'] = sprintf( /* translators: %s: form */ |
| 1416 | - __( 'Form %s not found.', 'give' ), $args['form'] ); | |
| 1491 | + __( 'Form %s not found.', 'give' ), | |
| 1492 | + $args['form'] | |
| 1493 | + ); | |
| 1417 | 1494 | } |
| 1418 | 1495 | }// End if(). |
| 1419 | 1496 | |
| 1420 | 1497 | if ( ! empty( $error ) ) { |
| @@ -1499,9 +1576,8 @@ | ||
| 1499 | 1576 | */ |
| 1500 | 1577 | switch ( $wp_query->query_vars['date'] ) { |
| 1501 | 1578 | |
| 1502 | 1579 | case 'today': |
| 1503 | - | |
| 1504 | 1580 | // Set and Format Start and End Date to be date of today. |
| 1505 | 1581 | $start_date = $end_date = date( 'Y/m/d', $current_time ); |
| 1506 | 1582 | |
| 1507 | 1583 | break; |
| @@ -1506,9 +1582,8 @@ | ||
| 1506 | 1582 | |
| 1507 | 1583 | break; |
| 1508 | 1584 | |
| 1509 | 1585 | case 'yesterday': |
| 1510 | - | |
| 1511 | 1586 | // Set and Format Start and End Date to be date of yesterday. |
| 1512 | 1587 | $start_date = $end_date = date( 'Y/m', $current_time ) . '/' . ( date( 'd', $current_time ) - 1 ); |
| 1513 | 1588 | |
| 1514 | 1589 | break; |
| @@ -1513,9 +1588,8 @@ | ||
| 1513 | 1588 | |
| 1514 | 1589 | break; |
| 1515 | 1590 | |
| 1516 | 1591 | case 'range': |
| 1517 | - | |
| 1518 | 1592 | // Format Start Date and End Date for filtering payment based on date range. |
| 1519 | 1593 | $start_date = $dates['year'] . '/' . $dates['m_start'] . '/' . $dates['day_start']; |
| 1520 | 1594 | $end_date = $dates['year_end'] . '/' . $dates['m_end'] . '/' . $dates['day_end']; |
| 1521 | 1595 | |
| @@ -1545,11 +1619,9 @@ | ||
| 1545 | 1619 | $i = 0; |
| 1546 | 1620 | foreach ( $query as $payment ) { |
| 1547 | 1621 | |
| 1548 | 1622 | if ( is_numeric( $payment ) ) { |
| 1549 | - $payment = new Give_Payment( $payment ); | |
| 1550 | - $payment_meta = $payment->get_meta(); | |
| 1551 | - $user_info = $payment->user_info; | |
| 1623 | + $payment = new Give_Payment( $payment ); | |
| 1552 | 1624 | } |
| 1553 | 1625 | |
| 1554 | 1626 | $payment_meta = $payment->get_meta(); |
| 1555 | 1627 | $user_info = $payment->user_info; |
| @@ -1560,12 +1632,17 @@ | ||
| 1560 | 1632 | $donations['donations'][ $i ]['ID'] = $payment->ID; |
| 1561 | 1633 | $donations['donations'][ $i ]['number'] = $payment->number; |
| 1562 | 1634 | $donations['donations'][ $i ]['transaction_id'] = $payment->transaction_id; |
| 1563 | 1635 | $donations['donations'][ $i ]['key'] = $payment->key; |
| 1564 | - $donations['donations'][ $i ]['total'] = $payment->total; | |
| 1636 | + $donations['donations'][ $i ]['total'] = give_format_decimal( | |
| 1637 | + array( | |
| 1638 | + 'donation_id' => $payment->ID, | |
| 1639 | + 'dp' => true, | |
| 1640 | + ) | |
| 1641 | + ); | |
| 1565 | 1642 | $donations['donations'][ $i ]['status'] = give_get_payment_status( $payment, true ); |
| 1566 | 1643 | $donations['donations'][ $i ]['gateway'] = $payment->gateway; |
| 1567 | - $donations['donations'][ $i ]['name'] = $first_name . ' ' . $last_name; | |
| 1644 | + $donations['donations'][ $i ]['name'] = trim( "{$first_name} {$last_name}" ); | |
| 1568 | 1645 | $donations['donations'][ $i ]['fname'] = $first_name; |
| 1569 | 1646 | $donations['donations'][ $i ]['lname'] = $last_name; |
| 1570 | 1647 | $donations['donations'][ $i ]['email'] = $payment->email; |
| 1571 | 1648 | $donations['donations'][ $i ]['date'] = $payment->date; |
| @@ -1576,39 +1653,68 @@ | ||
| 1576 | 1653 | $price_id = isset( $payment_meta['price_id'] ) ? $payment_meta['price_id'] : null; |
| 1577 | 1654 | |
| 1578 | 1655 | $donations['donations'][ $i ]['form']['id'] = $form_id; |
| 1579 | 1656 | $donations['donations'][ $i ]['form']['name'] = get_the_title( $payment_meta['form_id'] ); |
| 1580 | - $donations['donations'][ $i ]['form']['price'] = $price; | |
| 1657 | + $donations['donations'][ $i ]['form']['price'] = give_format_decimal( | |
| 1658 | + array( | |
| 1659 | + 'amount' => $price, | |
| 1660 | + 'currency' => give_get_option( 'currency' ), | |
| 1661 | + 'dp' => true, | |
| 1662 | + ) | |
| 1663 | + ); | |
| 1581 | 1664 | |
| 1582 | 1665 | if ( give_has_variable_prices( $form_id ) ) { |
| 1583 | 1666 | if ( isset( $payment_meta['price_id'] ) ) { |
| 1584 | - $price_name = give_get_price_option_name( $form_id, $payment_meta['price_id'], $payment->ID ); | |
| 1667 | + $price_name = give_get_price_option_name( $form_id, $payment_meta['price_id'], $payment->ID ); | |
| 1585 | 1668 | $donations['donations'][ $i ]['form']['price_name'] = $price_name; |
| 1586 | 1669 | $donations['donations'][ $i ]['form']['price_id'] = $price_id; |
| 1587 | - $donations['donations'][ $i ]['form']['price'] = give_get_price_option_amount( $form_id, $price_id ); | |
| 1588 | - | |
| 1670 | + $donations['donations'][ $i ]['form']['price'] = give_format_decimal( | |
| 1671 | + array( | |
| 1672 | + 'amount' => give_get_price_option_amount( $form_id, $price_id ), | |
| 1673 | + 'currency' => give_get_option( 'currency' ), | |
| 1674 | + 'dp' => true, | |
| 1675 | + ) | |
| 1676 | + ); | |
| 1589 | 1677 | } |
| 1590 | 1678 | } |
| 1591 | 1679 | |
| 1592 | - if( ! empty( $payment_meta ) ) { | |
| 1680 | + if ( ! empty( $payment_meta ) ) { | |
| 1593 | 1681 | // Add custom meta to API |
| 1594 | 1682 | foreach ( $payment_meta as $meta_key => $meta_value ) { |
| 1595 | 1683 | |
| 1596 | 1684 | $exceptions = array( |
| 1685 | + '_give_payment_form_title', | |
| 1597 | 1686 | 'form_title', |
| 1687 | + '_give_payment_form_id', | |
| 1598 | 1688 | 'form_id', |
| 1689 | + '_give_payment_price_id', | |
| 1599 | 1690 | 'price_id', |
| 1600 | 1691 | 'user_info', |
| 1692 | + '_give_payment_purchase_key', | |
| 1601 | 1693 | 'key', |
| 1602 | 1694 | 'email', |
| 1603 | 1695 | 'date', |
| 1696 | + 'currency', | |
| 1697 | + '_give_payment_total', | |
| 1698 | + '_give_payment_date', | |
| 1604 | 1699 | ); |
| 1605 | 1700 | |
| 1606 | 1701 | // Don't clutter up results with dupes |
| 1607 | - if ( in_array( $meta_key, $exceptions ) ) { | |
| 1702 | + if ( ! is_string( $meta_value ) || in_array( $meta_key, $exceptions ) ) { | |
| 1608 | 1703 | continue; |
| 1609 | 1704 | } |
| 1610 | 1705 | |
| 1706 | + // Meta key can contain price value like _give_fee_amount, so convert them to standard format. | |
| 1707 | + if ( give_is_amount_sanitized( $meta_value ) ) { | |
| 1708 | + $meta_value = give_format_decimal( | |
| 1709 | + array( | |
| 1710 | + 'amount' => $meta_value, | |
| 1711 | + 'currency' => give_get_option( 'currency' ), | |
| 1712 | + 'dp' => true, | |
| 1713 | + ) | |
| 1714 | + ); | |
| 1715 | + } | |
| 1716 | + | |
| 1611 | 1717 | $donations['donations'][ $i ]['payment_meta'][ $meta_key ] = $meta_value; |
| 1612 | 1718 | |
| 1613 | 1719 | } |
| 1614 | 1720 | } |
| @@ -1646,9 +1752,9 @@ | ||
| 1646 | 1752 | * @since 1.1 |
| 1647 | 1753 | * |
| 1648 | 1754 | * @global WP_Query $wp_query |
| 1649 | 1755 | * |
| 1650 | - * @param array $data | |
| 1756 | + * @param array $data | |
| 1651 | 1757 | * |
| 1652 | 1758 | * @return void |
| 1653 | 1759 | */ |
| 1654 | 1760 | private function log_request( $data = array() ) { |
| @@ -1714,9 +1820,9 @@ | ||
| 1714 | 1820 | * |
| 1715 | 1821 | * @since 1.1 |
| 1716 | 1822 | * @global WP_Query $wp_query |
| 1717 | 1823 | * |
| 1718 | - * @param int $status_code | |
| 1824 | + * @param int $status_code | |
| 1719 | 1825 | */ |
| 1720 | 1826 | public function output( $status_code = 200 ) { |
| 1721 | 1827 | |
| 1722 | 1828 | $format = $this->get_output_format(); |
| @@ -1735,10 +1841,9 @@ | ||
| 1735 | 1841 | do_action( 'give_api_output_before', $this->data, $this, $format ); |
| 1736 | 1842 | |
| 1737 | 1843 | switch ( $format ) : |
| 1738 | 1844 | |
| 1739 | - case 'xml' : | |
| 1740 | - | |
| 1845 | + case 'xml': | |
| 1741 | 1846 | require_once GIVE_PLUGIN_DIR . 'includes/libraries/array2xml.php'; |
| 1742 | 1847 | $xml = Array2XML::createXML( 'give', $this->data ); |
| 1743 | 1848 | echo $xml->saveXML(); |
| 1744 | 1849 | |
| @@ -1743,10 +1848,9 @@ | ||
| 1743 | 1848 | echo $xml->saveXML(); |
| 1744 | 1849 | |
| 1745 | 1850 | break; |
| 1746 | 1851 | |
| 1747 | - case 'json' : | |
| 1748 | - | |
| 1852 | + case 'json': | |
| 1749 | 1853 | header( 'Content-Type: application/json' ); |
| 1750 | 1854 | if ( ! empty( $this->pretty_print ) ) { |
| 1751 | 1855 | echo json_encode( $this->data, $this->pretty_print ); |
| 1752 | 1856 | } else { |
| @@ -1754,10 +1858,9 @@ | ||
| 1754 | 1858 | } |
| 1755 | 1859 | |
| 1756 | 1860 | break; |
| 1757 | 1861 | |
| 1758 | - default : | |
| 1759 | - | |
| 1862 | + default: | |
| 1760 | 1863 | /** |
| 1761 | 1864 | * Fires by the API while outputting other formats. |
| 1762 | 1865 | * |
| 1763 | 1866 | * @since 1.1 |
| @@ -1806,9 +1909,9 @@ | ||
| 1806 | 1909 | <table class="form-table"> |
| 1807 | 1910 | <tbody> |
| 1808 | 1911 | <tr> |
| 1809 | 1912 | <th> |
| 1810 | - <?php _e( 'Give API Keys', 'give' ); ?> | |
| 1913 | + <?php _e( 'GiveWP API Keys', 'give' ); ?> | |
| 1811 | 1914 | </th> |
| 1812 | 1915 | <td> |
| 1813 | 1916 | <?php |
| 1814 | 1917 | $public_key = $this->get_user_public_key( $user->ID ); |
| @@ -1815,9 +1918,9 @@ | ||
| 1815 | 1918 | $secret_key = $this->get_user_secret_key( $user->ID ); |
| 1816 | 1919 | ?> |
| 1817 | 1920 | <?php if ( empty( $user->give_user_public_key ) ) { ?> |
| 1818 | 1921 | <input name="give_set_api_key" type="checkbox" id="give_set_api_key" /> |
| 1819 | - <span class="description"><?php _e( 'Generate API Key', 'give' ); ?></span> | |
| 1922 | + <span class="description"><label for="give_set_api_key"><?php _e( 'Generate API Key', 'give' ); ?></label></span> | |
| 1820 | 1923 | <?php } else { ?> |
| 1821 | 1924 | <strong style="display:inline-block; width: 125px;"><?php _e( 'Public key:', 'give' ); ?> |
| 1822 | 1925 | </strong> |
| 1823 | 1926 | <input type="text" disabled="disabled" class="regular-text" id="publickey" value="<?php echo esc_attr( $public_key ); ?>" /> |
| @@ -1836,9 +1939,10 @@ | ||
| 1836 | 1939 | </td> |
| 1837 | 1940 | </tr> |
| 1838 | 1941 | </tbody> |
| 1839 | 1942 | </table> |
| 1840 | - <?php }// End if(). | |
| 1943 | + <?php | |
| 1944 | + }// End if(). | |
| 1841 | 1945 | } |
| 1842 | 1946 | |
| 1843 | 1947 | /** |
| 1844 | 1948 | * Process an API key generation/revocation |
| @@ -1852,17 +1956,25 @@ | ||
| 1852 | 1956 | */ |
| 1853 | 1957 | public function process_api_key( $args ) { |
| 1854 | 1958 | |
| 1855 | 1959 | if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'give-api-nonce' ) ) { |
| 1856 | - wp_die( __( 'Nonce verification failed.', 'give' ), __( 'Error', 'give' ), array( | |
| 1857 | - 'response' => 403, | |
| 1858 | - ) ); | |
| 1960 | + wp_die( | |
| 1961 | + __( 'We\'re unable to recognize your session. Please refresh the screen to try again; otherwise contact your website administrator for assistance.', 'give' ), | |
| 1962 | + __( 'Error', 'give' ), | |
| 1963 | + array( | |
| 1964 | + 'response' => 403, | |
| 1965 | + ) | |
| 1966 | + ); | |
| 1859 | 1967 | } |
| 1860 | 1968 | |
| 1861 | 1969 | if ( empty( $args['user_id'] ) ) { |
| 1862 | - wp_die( __( 'User ID Required.', 'give' ), __( 'Error', 'give' ), array( | |
| 1863 | - 'response' => 401, | |
| 1864 | - ) ); | |
| 1970 | + wp_die( | |
| 1971 | + __( 'User ID Required.', 'give' ), | |
| 1972 | + __( 'Error', 'give' ), | |
| 1973 | + array( | |
| 1974 | + 'response' => 401, | |
| 1975 | + ) | |
| 1976 | + ); | |
| 1865 | 1977 | } |
| 1866 | 1978 | |
| 1867 | 1979 | if ( is_numeric( $args['user_id'] ) ) { |
| 1868 | 1980 | $user_id = isset( $args['user_id'] ) ? absint( $args['user_id'] ) : get_current_user_id(); |
| @@ -1872,17 +1984,29 @@ | ||
| 1872 | 1984 | } |
| 1873 | 1985 | $process = isset( $args['give_api_process'] ) ? strtolower( $args['give_api_process'] ) : false; |
| 1874 | 1986 | |
| 1875 | 1987 | if ( $user_id == get_current_user_id() && ! give_get_option( 'allow_user_api_keys' ) && ! current_user_can( 'manage_give_settings' ) ) { |
| 1876 | - wp_die( sprintf( /* translators: %s: process */ | |
| 1877 | - __( 'You do not have permission to %s API keys for this user.', 'give' ), $process ), __( 'Error', 'give' ), array( | |
| 1878 | - 'response' => 403, | |
| 1879 | - ) ); | |
| 1988 | + wp_die( | |
| 1989 | + sprintf( /* translators: %s: process */ | |
| 1990 | + __( 'You do not have permission to %s API keys for this user.', 'give' ), | |
| 1991 | + $process | |
| 1992 | + ), | |
| 1993 | + __( 'Error', 'give' ), | |
| 1994 | + array( | |
| 1995 | + 'response' => 403, | |
| 1996 | + ) | |
| 1997 | + ); | |
| 1880 | 1998 | } elseif ( ! current_user_can( 'manage_give_settings' ) ) { |
| 1881 | - wp_die( sprintf( /* translators: %s: process */ | |
| 1882 | - __( 'You do not have permission to %s API keys for this user.', 'give' ), $process ), __( 'Error', 'give' ), array( | |
| 1883 | - 'response' => 403, | |
| 1884 | - ) ); | |
| 1999 | + wp_die( | |
| 2000 | + sprintf( /* translators: %s: process */ | |
| 2001 | + __( 'You do not have permission to %s API keys for this user.', 'give' ), | |
| 2002 | + $process | |
| 2003 | + ), | |
| 2004 | + __( 'Error', 'give' ), | |
| 2005 | + array( | |
| 2006 | + 'response' => 403, | |
| 2007 | + ) | |
| 2008 | + ); | |
| 1885 | 2009 | } |
| 1886 | 2010 | |
| 1887 | 2011 | switch ( $process ) { |
| 1888 | 2012 | case 'generate': |
| @@ -1887,12 +2011,12 @@ | ||
| 1887 | 2011 | switch ( $process ) { |
| 1888 | 2012 | case 'generate': |
| 1889 | 2013 | if ( $this->generate_api_key( $user_id ) ) { |
| 1890 | 2014 | Give_Cache::delete( Give_Cache::get_key( 'give_total_api_keys' ) ); |
| 1891 | - wp_redirect( add_query_arg( 'give-messages[]', 'api-key-generated', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) ); | |
| 2015 | + wp_redirect( esc_url_raw( add_query_arg( 'give-messages[]', 'api-key-generated', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) ) ); | |
| 1892 | 2016 | exit(); |
| 1893 | 2017 | } else { |
| 1894 | - wp_redirect( add_query_arg( 'give-messages[]', 'api-key-failed', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) ); | |
| 2018 | + wp_redirect( esc_url_raw( add_query_arg( 'give-messages[]', 'api-key-failed', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) ) ); | |
| 1895 | 2019 | exit(); |
| 1896 | 2020 | } |
| 1897 | 2021 | break; |
| 1898 | 2022 | case 'regenerate': |
| @@ -1897,15 +2021,15 @@ | ||
| 1897 | 2021 | break; |
| 1898 | 2022 | case 'regenerate': |
| 1899 | 2023 | $this->generate_api_key( $user_id, true ); |
| 1900 | 2024 | Give_Cache::delete( Give_Cache::get_key( 'give_total_api_keys' ) ); |
| 1901 | - wp_redirect( add_query_arg( 'give-messages[]', 'api-key-regenerated', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) ); | |
| 2025 | + wp_redirect( esc_url_raw( add_query_arg( 'give-messages[]', 'api-key-regenerated', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) ) ); | |
| 1902 | 2026 | exit(); |
| 1903 | 2027 | break; |
| 1904 | 2028 | case 'revoke': |
| 1905 | 2029 | $this->revoke_api_key( $user_id ); |
| 1906 | 2030 | Give_Cache::delete( Give_Cache::get_key( 'give_total_api_keys' ) ); |
| 1907 | - wp_redirect( add_query_arg( 'give-messages[]', 'api-key-revoked', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) ); | |
| 2031 | + wp_redirect( esc_url_raw( add_query_arg( 'give-messages[]', 'api-key-revoked', 'edit.php?post_type=give_forms&page=give-tools&tab=api' ) ) ); | |
| 1908 | 2032 | exit(); |
| 1909 | 2033 | break; |
| 1910 | 2034 | default; |
| 1911 | 2035 | break; |
| @@ -1939,11 +2063,11 @@ | ||
| 1939 | 2063 | |
| 1940 | 2064 | $new_public_key = ''; |
| 1941 | 2065 | $new_secret_key = ''; |
| 1942 | 2066 | |
| 1943 | - if( ! empty( $_POST['from'] ) && 'profile' === $_POST['from'] ) { | |
| 2067 | + if ( ! empty( $_POST['from'] ) && 'profile' === $_POST['from'] ) { | |
| 1944 | 2068 | // For User Profile Page. |
| 1945 | - if( ! empty( $_POST['give_set_api_key'] ) ) { | |
| 2069 | + if ( ! empty( $_POST['give_set_api_key'] ) ) { | |
| 1946 | 2070 | // Generate API Key from User Profile page. |
| 1947 | 2071 | $new_public_key = $this->generate_public_key( $user->user_email ); |
| 1948 | 2072 | $new_secret_key = $this->generate_private_key( $user->ID ); |
| 1949 | 2073 | } elseif ( ! empty( $_POST['give_revoke_api_key'] ) ) { |
| @@ -2091,19 +2215,40 @@ | ||
| 2091 | 2215 | /** |
| 2092 | 2216 | * Generate the default earnings stats returned by the 'stats' endpoint |
| 2093 | 2217 | * |
| 2094 | 2218 | * @access private |
| 2219 | + * @return array default earnings statistics | |
| 2095 | 2220 | * @since 1.1 |
| 2096 | - * @return array default earnings statistics | |
| 2097 | 2221 | */ |
| 2098 | 2222 | private function get_default_earnings_stats() { |
| 2223 | + $currency = give_get_option( 'currency' ); | |
| 2099 | 2224 | |
| 2100 | 2225 | // Default earnings return |
| 2101 | 2226 | $earnings = array(); |
| 2102 | - $earnings['earnings']['today'] = $this->stats->get_earnings( 0, 'today' ); | |
| 2103 | - $earnings['earnings']['current_month'] = $this->stats->get_earnings( 0, 'this_month' ); | |
| 2104 | - $earnings['earnings']['last_month'] = $this->stats->get_earnings( 0, 'last_month' ); | |
| 2105 | - $earnings['earnings']['totals'] = give_get_total_earnings(); | |
| 2227 | + $earnings['earnings']['today'] = give_format_decimal( | |
| 2228 | + array( | |
| 2229 | + 'amount' => $this->stats->get_earnings( 0, 'today' ), | |
| 2230 | + 'currency' => $currency, | |
| 2231 | + ) | |
| 2232 | + ); | |
| 2233 | + $earnings['earnings']['current_month'] = give_format_decimal( | |
| 2234 | + array( | |
| 2235 | + 'amount' => $this->stats->get_earnings( 0, 'this_month' ), | |
| 2236 | + 'currency' => $currency, | |
| 2237 | + ) | |
| 2238 | + ); | |
| 2239 | + $earnings['earnings']['last_month'] = give_format_decimal( | |
| 2240 | + array( | |
| 2241 | + 'amount' => $this->stats->get_earnings( 0, 'last_month' ), | |
| 2242 | + 'currency' => $currency, | |
| 2243 | + ) | |
| 2244 | + ); | |
| 2245 | + $earnings['earnings']['totals'] = give_format_decimal( | |
| 2246 | + array( | |
| 2247 | + 'amount' => give_get_total_earnings(), | |
| 2248 | + 'currency' => $currency, | |
| 2249 | + ) | |
| 2250 | + ); | |
| 2106 | 2251 | |
| 2107 | 2252 | return $earnings; |
| 2108 | 2253 | } |
| 2109 | 2254 | |
| @@ -2144,6 +2289,5 @@ | ||
| 2144 | 2289 | |
| 2145 | 2290 | return $return; |
| 2146 | 2291 | |
| 2147 | 2292 | } |
| 2148 | - | |
| 2149 | 2293 | } |