$status, 'search' => $search, 'tests' => $tests ), $page, self::PER_PAGE ); echo '
'; echo ' '; echo ' '; echo '
'; Admin::form( 'sg_export_csv', array(), 'sg-inline' ); echo ''; echo '

Donors who chose to be anonymous are shown as "Anonymous". Their name is never stored. Test donations are marked TEST and left out of the CSV and your totals.

'; if ( ! $res['rows'] ) { echo '

No donations found.

'; Admin::close(); return; } $goals = array(); foreach ( Store::goals()->all() as $g ) { $goals[ (int) $g['id'] ] = (string) $g['title']; } echo Admin::tableOpen( array( 'Date', 'Donor', 'Amount', 'Fee', 'Total paid', 'Goal', 'Status', 'Message' ), 'Donations', false ); foreach ( $res['rows'] as $r ) { $cur = Format::currency( $r['currency'] ); $test = Format::isTest( $r ); echo '' . Admin::td( 'Date' ) . esc_html( self::fmtDate( (string) $r['created_at'] ) ) . ''; echo Admin::td( 'Donor' ) . esc_html( Format::donorName( $r ) ) . ( $test ? ' TEST' : '' ) . ''; echo Admin::td( 'Amount' ) . esc_html( Format::money( (int) $r['base_minor'], $cur ) ) . '' . Admin::td( 'Fee' ) . esc_html( Format::money( (int) $r['fee_minor'], $cur ) ) . '' . Admin::td( 'Total paid' ) . esc_html( Format::money( (int) $r['total_minor'], $cur ) ) . ''; echo Admin::td( 'Goal' ) . esc_html( $test ? '(test)' : ( $goals[ (int) $r['goal_id'] ] ?? '#' . (int) $r['goal_id'] ) ) . ''; echo Admin::td( 'Status' ) . esc_html( ucfirst( (string) $r['status'] ) ) . ( 'approved' === $r['moderation'] ? '' : ' message ' . esc_html( (string) $r['moderation'] ) . '' ) . ''; echo Admin::td( 'Message' ) . esc_html( (string) $r['message'] ) . ''; } echo Admin::tableClose(); $pages = (int) ceil( $res['total'] / self::PER_PAGE ); if ( $pages > 1 ) { echo '
' . wp_kses_post( (string) paginate_links( array( 'base' => add_query_arg( 'paged', '%#%' ), 'format' => '', 'current' => $page, 'total' => $pages, 'prev_text' => '«', 'next_text' => '»', ) ) ) . '
'; } echo '

' . (int) $res['total'] . ' donation(s).

'; Admin::close(); } public static function renderModeration(): void { Admin::open( 'Message moderation' ); if ( ! Settings::get( 'moderate_messages' ) ) { echo '

Message moderation is currently off in Settings, so new messages are shown without review. Anything still waiting below was submitted while it was on.

'; } echo '

Approved messages can appear in alerts. Rejected messages are hidden. The donation itself still counts towards your goal either way.

'; $res = Store::searchDonations( array( 'status' => 'completed', 'moderation' => 'pending' ), 1, 100 ); if ( ! $res['rows'] ) { echo '

Nothing waiting for review.

'; Admin::close(); return; } echo Admin::tableOpen( array( 'Date', 'Donor', 'Amount', 'Message', 'Decision' ), 'Messages waiting for review' ); foreach ( $res['rows'] as $r ) { $cur = Format::currency( $r['currency'] ); echo '' . Admin::td( 'Date' ) . esc_html( self::fmtDate( (string) $r['created_at'] ) ) . '' . Admin::td( 'Donor' ) . esc_html( Format::donorName( $r ) ) . ''; echo Admin::td( 'Amount' ) . esc_html( Format::money( (int) $r['base_minor'], $cur ) ) . '' . Admin::td( 'Message' ) . esc_html( (string) $r['message'] ) . '' . Admin::td( 'Decision', 'sg-actions' ); foreach ( array( 'approved' => 'Approve', 'rejected' => 'Reject' ) as $to => $lbl ) { Admin::form( 'sg_moderate', array( 'donation_id' => (int) $r['id'], 'decision' => $to ), 'sg-inline' ); echo ' '; } echo ''; } echo Admin::tableClose(); Admin::close(); } public static function handleModerate(): void { Admin::guard( 'sg_moderate' ); $post = Admin::post_raw(); $id = isset( $post['donation_id'] ) ? absint( $post['donation_id'] ) : 0; $to = isset( $post['decision'] ) && is_string( $post['decision'] ) ? $post['decision'] : ''; $ok = $id && Store::setModeration( $id, $to ); Admin::redirect( Admin::url( 'streamgoals-moderation' ), $ok ? 'success' : 'error', $ok ? ( 'approved' === $to ? 'Message approved.' : 'Message rejected.' ) : 'That message could not be updated (it may already be reviewed).' ); } public static function handleExport(): void { Admin::guard( 'sg_export_csv' ); $goals = array(); foreach ( Store::goals()->all() as $g ) { $goals[ (int) $g['id'] ] = (string) $g['title']; } nocache_headers(); header( 'Content-Type: text/csv; charset=utf-8' ); header( 'Content-Disposition: attachment; filename="streamgoals-donations-' . gmdate( 'Y-m-d' ) . '.csv"' ); header( 'X-Content-Type-Options: nosniff' ); echo "\xEF\xBB\xBF"; // UTF-8 BOM so Excel reads accents correctly echo Csv::line( array( 'ID', 'Date (UTC)', 'Goal', 'Donor', 'Amount', 'Fee covered', 'Total paid', 'Currency', 'Status', 'Message status', 'Message', 'PayPal order', 'PayPal capture' ) ); // phpcs:ignore WordPress.Security.EscapeOutput -- CSV, not HTML $after = 0; do { $rows = Store::exportBatch( $after, 500 ); foreach ( $rows as $r ) { $after = (int) $r['id']; $cur = Format::currency( $r['currency'] ); echo Csv::line( array( // phpcs:ignore WordPress.Security.EscapeOutput $r['id'], $r['created_at'], $goals[ (int) $r['goal_id'] ] ?? '', Format::donorName( $r ), Format::decimal( (int) $r['base_minor'], $cur ), Format::decimal( (int) $r['fee_minor'], $cur ), Format::decimal( (int) $r['total_minor'], $cur ), $cur, $r['status'], $r['moderation'], $r['message'], $r['paypal_order_id'], $r['paypal_capture_id'], ) ); } } while ( count( $rows ) === 500 ); exit; } }