AyeCode /
invoicing
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Contains the class that exports subscriptions. |
||
| 4 | * |
||
| 5 | * |
||
| 6 | */ |
||
| 7 | |||
| 8 | defined( 'ABSPATH' ) || exit; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * GetPaid_Subscription_Exporter Class. |
||
| 12 | */ |
||
| 13 | class GetPaid_Subscription_Exporter extends GetPaid_Graph_Downloader { |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Retrieves subscription query args. |
||
| 17 | * |
||
| 18 | * @param array $args Args to search for. |
||
| 19 | * @return array |
||
| 20 | */ |
||
| 21 | public function get_subscription_query_args( $args ) { |
||
| 22 | |||
| 23 | $query_args = array( |
||
| 24 | 'status' => 'all', |
||
| 25 | 'number' => -1, |
||
| 26 | 'count_total' => false, |
||
| 27 | 'fields' => 'all', |
||
| 28 | ); |
||
| 29 | |||
| 30 | if ( ! empty( $args['status'] ) && in_array( $args['status'], array_keys( getpaid_get_subscription_statuses() ), true ) ) { |
||
| 31 | $query_args['status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) ); |
||
| 32 | } |
||
| 33 | |||
| 34 | $date_query = array(); |
||
| 35 | if ( ! empty( $args['to_date'] ) ) { |
||
| 36 | $date_query['before'] = wpinv_clean( $args['to_date'] ); |
||
| 37 | } |
||
| 38 | |||
| 39 | if ( ! empty( $args['from_date'] ) ) { |
||
| 40 | $date_query['after'] = wpinv_clean( $args['from_date'] ); |
||
| 41 | } |
||
| 42 | |||
| 43 | if ( ! empty( $date_query ) ) { |
||
| 44 | $date_query['inclusive'] = true; |
||
| 45 | $query_args['date_created_query'] = array( $date_query ); |
||
| 46 | } |
||
| 47 | |||
| 48 | return $query_args; |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Retrieves subscriptions. |
||
| 53 | * |
||
| 54 | * @param array $query_args GetPaid_Subscriptions_Query args. |
||
| 55 | * @return WPInv_Subscription[] |
||
| 56 | */ |
||
| 57 | public function get_subscriptions( $query_args ) { |
||
| 58 | |||
| 59 | // Get subscriptions. |
||
| 60 | $subscriptions = new GetPaid_Subscriptions_Query( $query_args ); |
||
| 61 | |||
| 62 | // Prepare the results. |
||
| 63 | return $subscriptions->get_results(); |
||
| 64 | |||
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Handles the actual download. |
||
| 69 | * |
||
| 70 | */ |
||
| 71 | public function export( $post_type, $args ) { |
||
| 72 | |||
| 73 | $subscriptions = $this->get_subscriptions( $this->get_subscription_query_args( $args ) ); |
||
| 74 | $stream = $this->prepare_output(); |
||
| 75 | $headers = $this->get_export_fields(); |
||
| 76 | $file_type = $this->prepare_file_type( 'subscriptions' ); |
||
| 77 | |||
| 78 | if ( 'csv' == $file_type ) { |
||
| 79 | $this->download_csv( $subscriptions, $stream, $headers ); |
||
| 80 | } elseif ( 'xml' == $file_type ) { |
||
| 81 | $this->download_xml( $subscriptions, $stream, $headers ); |
||
| 82 | } else { |
||
| 83 | $this->download_json( $subscriptions, $stream, $headers ); |
||
| 84 | } |
||
| 85 | |||
| 86 | fclose( $stream ); |
||
| 87 | exit; |
||
|
0 ignored issues
–
show
|
|||
| 88 | } |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Prepares a single subscription for download. |
||
| 92 | * |
||
| 93 | * @param WPInv_Subscription $subscription The subscription to prepare.. |
||
| 94 | * @param array $fields The fields to stream. |
||
| 95 | * @since 1.0.19 |
||
| 96 | * @return array |
||
| 97 | */ |
||
| 98 | public function prepare_row( $subscription, $fields ) { |
||
| 99 | |||
| 100 | $prepared = array(); |
||
| 101 | $amount_fields = $this->get_amount_fields(); |
||
| 102 | $invoice = $subscription->get_parent_payment(); |
||
| 103 | |||
| 104 | foreach ( $fields as $field ) { |
||
| 105 | |||
| 106 | $value = ''; |
||
| 107 | $method = "get_$field"; |
||
| 108 | |||
| 109 | if ( 0 === stripos( $field, 'customer' ) || 'currency' === $field ) { |
||
| 110 | |||
| 111 | if ( method_exists( $invoice, $method ) ) { |
||
| 112 | $value = $invoice->$method(); |
||
| 113 | } |
||
| 114 | } elseif ( method_exists( $subscription, $method ) ) { |
||
| 115 | $value = $subscription->$method(); |
||
| 116 | } |
||
| 117 | |||
| 118 | if ( in_array( $field, $amount_fields ) ) { |
||
| 119 | $value = wpinv_round_amount( wpinv_sanitize_amount( $value ) ); |
||
| 120 | } |
||
| 121 | |||
| 122 | $prepared[ $field ] = wpinv_clean( $value ); |
||
| 123 | |||
| 124 | } |
||
| 125 | |||
| 126 | return $prepared; |
||
| 127 | } |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Retrieves export fields. |
||
| 131 | * |
||
| 132 | * @since 1.0.19 |
||
| 133 | * @return array |
||
| 134 | */ |
||
| 135 | public function get_export_fields() { |
||
| 136 | |||
| 137 | $fields = array( |
||
| 138 | 'id', |
||
| 139 | 'currency', |
||
| 140 | 'initial_amount', |
||
| 141 | 'recurring_amount', |
||
| 142 | 'trial_period', |
||
| 143 | 'frequency', |
||
| 144 | 'period', |
||
| 145 | 'bill_times', |
||
| 146 | 'parent_payment_id', |
||
| 147 | 'profile_id', |
||
| 148 | 'product_id', |
||
| 149 | 'status', |
||
| 150 | 'date_created', |
||
| 151 | 'date_expires', |
||
| 152 | |||
| 153 | 'customer_id', |
||
| 154 | 'customer_first_name', |
||
| 155 | 'customer_last_name', |
||
| 156 | 'customer_phone', |
||
| 157 | 'customer_email', |
||
| 158 | 'customer_country', |
||
| 159 | 'customer_city', |
||
| 160 | 'customer_state', |
||
| 161 | 'customer_zip', |
||
| 162 | 'customer_company', |
||
| 163 | 'customer_vat_number', |
||
| 164 | 'customer_address', |
||
| 165 | |||
| 166 | ); |
||
| 167 | |||
| 168 | return apply_filters( 'getpaid_subscription_exporter_get_fields', $fields ); |
||
| 169 | } |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Retrieves amount fields. |
||
| 173 | * |
||
| 174 | * @since 1.0.19 |
||
| 175 | * @return array |
||
| 176 | */ |
||
| 177 | public function get_amount_fields() { |
||
| 178 | |||
| 179 | $fields = array( |
||
| 180 | 'initial_amount', |
||
| 181 | 'recurring_amount', |
||
| 182 | ); |
||
| 183 | |||
| 184 | return apply_filters( 'getpaid_subscription_exporter_get_amount_fields', $fields ); |
||
| 185 | } |
||
| 186 | |||
| 187 | } |
||
| 188 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.