Changeset 2298
- Timestamp:
- 01/15/2016 06:07:53 PM (9 years ago)
- Location:
- sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network/bootstrap.php
r2260 r2298 16 16 17 17 if ( is_admin() ) { 18 require_once( __DIR__ . '/includes/wordcamp-budgets-dashboard.php' ); 18 19 require_once( __DIR__ . '/includes/payment-requests-dashboard.php' ); 19 20 -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network/includes/payment-requests-dashboard.php
r2273 r2298 489 489 } 490 490 } 491 492 /**493 * Currency Conversion494 *495 * @param string $from What currency are we selling.496 * @param string $to What currency are we buying.497 * @param float $amount How much we're selling.498 *499 * @return float Converted amount.500 */501 public static function convert_currency( $from, $to, $amount ) {502 global $wpdb;503 504 $from = strtolower( $from );505 $to = strtolower( $to );506 $cache_key = md5( sprintf( 'wcp-exchange-rate-%s:%s', $from, $to ) );507 508 $rate = 0;509 if ( false === ( $rate = get_transient( $cache_key ) ) ) {510 $url = 'https://query.yahooapis.com/v1/public/yql';511 $url = add_query_arg( 'format', 'json', $url );512 $url = add_query_arg( 'env', rawurlencode( 'store://datatables.org/alltableswithkeys' ), $url );513 $url = add_query_arg( 'q', rawurlencode( $wpdb->prepare( 'select * from yahoo.finance.xchange where pair = %s', $from . $to ) ), $url );514 515 $request = wp_remote_get( esc_url_raw( $url ) );516 $body = json_decode( wp_remote_retrieve_body( $request ), true );517 518 if ( ! empty( $body['query']['results']['rate']['Ask'] ) ) {519 $rate = floatval( $body['query']['results']['rate']['Ask'] );520 }521 522 set_transient( $cache_key, $rate, 24 * HOUR_IN_SECONDS );523 }524 525 if ( $rate < 0.0000000001 )526 return 0;527 528 return $amount * $rate;529 }530 491 } -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network/includes/payment-requests-list-table.php
r2273 r2298 173 173 $amount = get_post_meta( $request->ID, '_camppayments_payment_amount', true ); 174 174 175 $amount = preg_replace( '#[^\d.-]+#', '', $amount ); 176 $amount = floatval( $amount ); 177 178 if ( strpos( $currency, 'null' ) === false && $amount ) { 179 $output = sprintf( '%s %s', esc_html( number_format( $amount, 2 ) ), esc_html( $currency ) ); 180 181 if ( $currency != 'USD' ) { 182 $usd_amount = Payment_Requests_Dashboard::convert_currency( $currency, 'usd', $amount ); 183 if ( $usd_amount ) 184 $output .= sprintf( '<br />~ %s USD', esc_html( number_format( $usd_amount, 2 ) ) ); 185 } 186 187 return $output; 188 } elseif ( $amount ) { 189 return esc_html( $amount ); 190 } 175 return wp_kses( 176 \WordCamp\Budgets_Dashboard\format_amount( $amount, $currency ), 177 array( 'br' => array() ) 178 ); 191 179 } 192 180
Note: See TracChangeset
for help on using the changeset viewer.