class-affiliates-affiliate-stats-renderer-wordpress.php
14 KB
<?php
class Affiliates_Affiliate_Stats_Renderer_WordPress extends Affiliates_Affiliate_Stats_Renderer { const IXAP183 = 'affiliate-stats-nonce'; const IXAP184 = 'affiliate-stats-nonce-1'; const IXAP185 = 'affiliate-stats-nonce-2'; const IXAP186 = 'affiliate-stats-nonce-filters'; static function render_referrals( $IXAP105 = array() ) { global $wpdb, $affiliates_options, $affiliates_db; $IXAP62 = ''; $IXAP24 = Affiliates_Affiliate_WordPress::get_user_affiliate_id(); if ( $IXAP24 === false ) { return $IXAP62; } $IXAP36 = $affiliates_options->get_option( 'affiliate_stats_referrals_from_date', null ); $IXAP38 = $affiliates_options->get_option( 'affiliate_stats_referrals_thru_date', null ); if ( isset( $_POST[self::IXAP186] ) ) { if ( !wp_verify_nonce( $_POST[self::IXAP186], plugin_basename( __FILE__ ) ) ) { wp_die( __( 'Access denied.', AFFILIATES_PRO_PLUGIN_DOMAIN ) ); } if ( isset( $_POST['clear_filters'] ) ) { $affiliates_options->delete_option( 'affiliate_stats_referrals_from_date' ); $affiliates_options->delete_option( 'affiliate_stats_referrals_thru_date' ); $IXAP36 = null; $IXAP38 = null; } else { if ( !empty( $_POST['from_date'] ) ) { $IXAP36 = date( 'Y-m-d', strtotime( $_POST['from_date'] ) ); $affiliates_options->update_option( 'affiliate_stats_referrals_from_date', $IXAP36 ); } if ( !empty( $_POST['thru_date'] ) ) { $IXAP38 = date( 'Y-m-d', strtotime( $_POST['thru_date'] ) ); $affiliates_options->update_option( 'affiliate_stats_referrals_thru_date', $IXAP38 ); } if ( $IXAP36 && $IXAP38 ) { if ( strtotime( $IXAP36 ) > strtotime( $IXAP38 ) ) { $IXAP38 = null; $affiliates_options->delete_option( 'affiliate_stats_referrals_thru_date' ); } } } } if ( $IXAP36 ) { $IXAP37 = DateHelper::u2s( $IXAP36 ); } if ( $IXAP38 ) { $IXAP39 = DateHelper::u2s( $IXAP38, 24*3600 ); } if ( isset( $_POST['row_count'] ) ) { if ( !wp_verify_nonce( $_POST[self::IXAP184], plugin_basename( __FILE__ ) ) ) { wp_die( __( 'Access denied.', AFFILIATES_PRO_PLUGIN_DOMAIN ) ); } } if ( isset( $_POST['paged'] ) ) { if ( !wp_verify_nonce( $_POST[self::IXAP185], plugin_basename( __FILE__ ) ) ) { wp_die( __( 'Access denied.', AFFILIATES_PRO_PLUGIN_DOMAIN ) ); } } $IXAP70 = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $IXAP70 = remove_query_arg( 'paged', $IXAP70 ); $IXAP47 = $affiliates_db->get_tablename( 'affiliates' ); $IXAP49 = $affiliates_db->get_tablename( 'referrals' ); $IXAP112 = $affiliates_db->get_tablename( 'hits' ); $posts_table = $wpdb->prefix . 'posts'; $IXAP187 = isset( $_POST['row_count'] ) ? intval( $_POST['row_count'] ) : 0; if ($IXAP187 <= 0) { $IXAP187 = $affiliates_options->get_option( 'affiliate_stats_referrals_per_page', self::IXAP188 ); } else { $affiliates_options->update_option( 'affiliate_stats_referrals_per_page', $IXAP187 ); } $IXAP189 = isset( $_GET['offset'] ) ? intval( $_GET['offset'] ) : 0; if ( $IXAP189 < 0 ) { $IXAP189 = 0; } $IXAP190 = isset( $_REQUEST['paged'] ) ? intval( $_REQUEST['paged'] ) : 0; if ( !isset( $_REQUEST['paged'] ) ) { $IXAP190 = intval( get_query_var( 'paged' ) ); } if ( $IXAP190 < 0 ) { $IXAP190 = 0; } $IXAP45 = isset( $_GET['orderby'] ) ? $_GET['orderby'] : null; switch ( $IXAP45 ) { case 'referral_id' : case 'reference' : case 'datetime' : case 'post_title' : case 'amount' : case 'currency_id' : case 'status' : break; default : $IXAP45 = 'datetime'; } $IXAP46 = isset( $_GET['order'] ) ? $_GET['order'] : null; switch ( $IXAP46 ) { case 'asc' : case 'ASC' : $IXAP191 = 'DESC'; break; case 'desc' : case 'DESC' : $IXAP191 = 'ASC'; break; default: $IXAP46 = 'DESC'; $IXAP191 = 'ASC'; } if ( $IXAP36 || $IXAP38 || $IXAP24 ) { $IXAP51 = " WHERE "; } else { $IXAP51 = ''; } $IXAP52 = array(); if ( $IXAP36 && $IXAP38 ) { $IXAP51 .= " datetime >= %s AND datetime < %s "; $IXAP52[] = $IXAP37; $IXAP52[] = $IXAP39; } else if ( $IXAP36 ) { $IXAP51 .= " datetime >= %s "; $IXAP52[] = $IXAP37; } else if ( $IXAP38 ) { $IXAP51 .= " datetime < %s "; $IXAP52[] = $IXAP39; } if ( $IXAP24 ) { if ( $IXAP36 || $IXAP38 ) { $IXAP51 .= " AND "; } $IXAP51 .= " r.affiliate_id = %d "; $IXAP52[] = $IXAP24; } $IXAP192 = isset( $IXAP105['show_accepted'] ) && ( ( $IXAP105['show_accepted'] === true ) || ( $IXAP105['show_accepted'] == 'true' ) ); $IXAP193 = isset( $IXAP105['show_pending'] ) && ( ( $IXAP105['show_pending'] === true ) || ( $IXAP105['show_pending'] == 'true' ) ); $IXAP194 = isset( $IXAP105['show_closed'] ) && ( ( $IXAP105['show_closed'] === true ) || ( $IXAP105['show_closed'] == 'true' ) ); $IXAP195 = isset( $IXAP105['show_rejected'] ) && ( ( $IXAP105['show_rejected'] === true ) || ( $IXAP105['show_rejected'] == 'true' ) ); $IXAP196 = 0; if ( $IXAP192 ) { $IXAP196++; $IXAP52[] = AFFILIATES_REFERRAL_STATUS_ACCEPTED; } if ( $IXAP193 ) { $IXAP196++; $IXAP52[] = AFFILIATES_REFERRAL_STATUS_PENDING; } if ( $IXAP194 ) { $IXAP196++; $IXAP52[] = AFFILIATES_REFERRAL_STATUS_CLOSED; } if ( $IXAP195 ) { $IXAP196++; $IXAP52[] = AFFILIATES_REFERRAL_STATUS_REJECTED; } if ( $IXAP36 || $IXAP38 || $IXAP24 ) { $IXAP51 .= " AND "; } switch ( $IXAP196 ) { case 1 : $IXAP51 .= " r.status = %s "; break; case 2 : $IXAP51 .= " r.status IN ( %s, %s ) "; break; case 3 : $IXAP51 .= " r.status IN ( %s, %s, %s ) "; break; case 4 : $IXAP51 .= " r.status IN ( %s, %s, %s, %s ) "; break; default : $IXAP51 .= " r.status = '' "; } $IXAP197 = $wpdb->prepare( "SELECT count(*) FROM $IXAP49 r
$IXAP51
", $IXAP52 ); $IXAP198 = $wpdb->get_var( $IXAP197 ); if ( $IXAP198 > $IXAP187 ) { $IXAP199 = true; } else { $IXAP199 = false; } $IXAP19 = ceil ( $IXAP198 / $IXAP187 ); if ( $IXAP190 > $IXAP19 ) { $IXAP190 = $IXAP19; } if ( $IXAP190 != 0 ) { $IXAP189 = ( $IXAP190 - 1 ) * $IXAP187; } $IXAP98 = $wpdb->prepare("
SELECT r.*
FROM $IXAP49 r
LEFT JOIN $IXAP47 a ON r.affiliate_id = a.affiliate_id
LEFT JOIN $posts_table p ON r.post_id = p.ID
$IXAP51
ORDER BY $IXAP45 $IXAP46
LIMIT $IXAP187 OFFSET $IXAP189
", $IXAP52 ); $IXAP55 = $wpdb->get_results( $IXAP98, OBJECT ); $IXAP62 .= '<div class="affiliate-stats referrals">'; $IXAP62 .= '
<div class="page-options">
<form id="setrowcount" action="" method="post">
<div>
<label for="row_count">' . __('Results per page', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</label>' . '<input name="row_count" type="text" size="2" value="' . esc_attr( $IXAP187 ) .'" />
' . wp_nonce_field( plugin_basename( __FILE__ ), self::IXAP184, true, false ) . '
<input type="submit" value="' . __( 'Apply', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '"/>
</div>
</form>
</div>
'; if ( $IXAP199 ) { $IXAP200 = new Affiliates_Pagination( $IXAP198, null, $IXAP187 ); $IXAP62 .= '<form id="posts-filter" method="post" action="">'; $IXAP62 .= '<div>'; $IXAP62 .= wp_nonce_field( plugin_basename( __FILE__ ), self::IXAP185, true, false ); $IXAP62 .= '</div>'; $IXAP62 .= '<div class="tablenav top">'; $IXAP62 .= $IXAP200->pagination( 'top' ); $IXAP62 .= '</div>'; $IXAP62 .= '</form>'; } $IXAP201 = isset( $IXAP105['show_post'] ) && ( ( $IXAP105['show_post'] === true ) || ( $IXAP105['show_post'] == 'true' ) ); $IXAP202 = isset( $IXAP105['show_referral_id'] ) && ( ( $IXAP105['show_referral_id'] === true ) || ( $IXAP105['show_referral_id'] == 'true' ) ); $IXAP203 = isset( $IXAP105['show_reference'] ) && ( ( $IXAP105['show_reference'] === true ) || ( $IXAP105['show_reference'] == 'true' ) ); $IXAP76 = array( 'datetime' => __( 'Date', AFFILIATES_PRO_PLUGIN_DOMAIN ) ); if ( $IXAP202 ) { $IXAP76['referral_id'] = __( 'ID', AFFILIATES_PRO_PLUGIN_DOMAIN ); } if ( $IXAP203 ) { $IXAP76['reference'] = __( 'Reference', AFFILIATES_PRO_PLUGIN_DOMAIN ); } if ( $IXAP201 ) { $IXAP76['post_title'] = __( 'Post', AFFILIATES_PRO_PLUGIN_DOMAIN ); } $IXAP204 = isset( $IXAP105['show_amount'] ) && ( ( $IXAP105['show_amount'] === true ) || ( $IXAP105['show_amount'] == 'true' ) ); if ( $IXAP204 ) { $IXAP76['amount'] = __( 'Amount', AFFILIATES_PRO_PLUGIN_DOMAIN ); } $IXAP205 = isset( $IXAP105['show_currency_id'] ) && ( ( $IXAP105['show_currency_id'] === true ) || ( $IXAP105['show_currency_id'] == 'true' ) ); if ( $IXAP205 ) { $IXAP76['currency_id'] = __( 'Currency', AFFILIATES_PRO_PLUGIN_DOMAIN ); } $IXAP206 = isset( $IXAP105['show_status'] ) && ( ( $IXAP105['show_status'] === true ) || ( $IXAP105['show_status'] == 'true' ) ); if ( $IXAP206 ) { $IXAP76['status'] = __( 'Status', AFFILIATES_PRO_PLUGIN_DOMAIN ); } if ( !empty( $IXAP105['data'] ) ) { $IXAP76['data'] = __( 'Details', AFFILIATES_PRO_PLUGIN_DOMAIN ); } $IXAP76 = apply_filters( 'affiliates_affiliate_stats_renderer_column_display_names', $IXAP76 ); $IXAP207 = count( $IXAP76 ); $IXAP62 .= '<table class="referrals" cellspacing="0" cellpadding="0">'; $IXAP62 .= '<thead>'; $IXAP62 .= '<tr>'; foreach ( $IXAP76 as $IXAP78 => $IXAP79 ) { $IXAP208 = array( 'orderby' => $IXAP78, 'order' => $IXAP191 ); if ( in_array( $IXAP78, array( 'referral_id', 'reference', 'datetime', 'post_title', 'amount', 'currency_id', 'status' ) ) ) { $IXAP143 = ""; if ( strcmp( $IXAP78, $IXAP45 ) == 0 ) { $IXAP209 = strtolower( $IXAP46 ); $IXAP143 = "$IXAP78 manage-column sorted $IXAP209"; } else { $IXAP143 = "$IXAP78 manage-column sortable"; } $IXAP79 = '<a href="' . esc_url( add_query_arg( $IXAP208, $IXAP70 ) ) . '"><span>' . $IXAP79 . '</span><span class="sorting-indicator"></span></a>'; $IXAP62 .= "<th scope='col' class='$IXAP143'>$IXAP79</th>"; } else { $IXAP62 .= "<th scope='col' class='$IXAP78'>$IXAP79</th>"; } } $IXAP62 .= '</tr>'; $IXAP62 .= '</thead>'; $IXAP62 .= '<tbody>'; if ( count( $IXAP55 ) > 0 ) { $IXAP210 = array(); if ( !empty( $IXAP105['data'] ) ) { $IXAP211 = explode(",", $IXAP105['data'] ); if ( !empty( $IXAP211 ) ) { foreach( $IXAP211 as $IXAP212 ) { $IXAP210[] = trim( $IXAP212 ); } } } $IXAP75 = array( AFFILIATES_REFERRAL_STATUS_ACCEPTED => __( 'Accepted', AFFILIATES_PLUGIN_DOMAIN ), AFFILIATES_REFERRAL_STATUS_CLOSED => __( 'Closed', AFFILIATES_PLUGIN_DOMAIN ), AFFILIATES_REFERRAL_STATUS_PENDING => __( 'Pending', AFFILIATES_PLUGIN_DOMAIN ), AFFILIATES_REFERRAL_STATUS_REJECTED => __( 'Rejected', AFFILIATES_PLUGIN_DOMAIN ), ); for ( $IXAP80 = 0; $IXAP80 < count( $IXAP55 ); $IXAP80++ ) { $IXAP15 = $IXAP55[$IXAP80]; $IXAP62 .= '<tr class="details-referrals ' . ( $IXAP80 % 2 == 0 ? 'even' : 'odd' ) . '">'; foreach( $IXAP76 as $IXAP78 => $IXAP79 ) { switch( $IXAP78 ) { case 'referral_id' : $IXAP62 .= '<td class="referral_id">' . wp_filter_nohtml_kses( $IXAP15->referral_id ) . '</td>'; break; case 'reference' : $IXAP62 .= '<td class="reference">' . wp_filter_nohtml_kses( $IXAP15->reference ) . '</td>'; break; case 'datetime' : $IXAP62 .= '<td class="datetime">' . DateHelper::s2u( $IXAP15->datetime ) . '</td>'; break; case 'post_title' : if ( $IXAP201 ) { if ( !empty( $IXAP15->post_id ) ) { $IXAP213 = get_permalink( $IXAP15->post_id ); $post_title = get_the_title( $IXAP15->post_id ); $IXAP62 .= '<td class="post_title"><a href="' . esc_attr( $IXAP213 ) . '" target="_blank">' . wp_filter_nohtml_kses( $post_title ) . '</a></td>'; } else { $IXAP62 .= '<td class="post_title"></td>'; } } break; case 'amount' : if ( $IXAP204 ) { $IXAP62 .= '<td class="amount">' . esc_attr( $IXAP15->amount ) . '</td>'; } break; case 'currency_id' : if ( $IXAP205 ) { $IXAP62 .= '<td class="currency_id">' . esc_attr( $IXAP15->currency_id ) . '</td>'; } break; case 'status' : if ( $IXAP206 ) { $IXAP62 .= '<td class="status">' . ( isset( $IXAP75[$IXAP15->status] ) ? $IXAP75[$IXAP15->status] : esc_attr( $IXAP15->status ) ) . '</td>'; } break; case 'data' : if ( !empty( $IXAP210 ) ) { $IXAP214 = $IXAP15->data; if ( !empty( $IXAP214 ) ) { $IXAP214 = unserialize( $IXAP214 ); } else { $IXAP214 = array(); } $IXAP214 = apply_filters( 'affiliates_affiliate_stats_renderer_data', $IXAP214, $IXAP15 ); $IXAP62 .= '<td>'; if ( $IXAP214 ) { $IXAP215 = ''; if ( is_array( $IXAP214 ) ) { foreach ( $IXAP210 as $IXAP78 ) { if ( isset( $IXAP214[$IXAP78] ) ) { $IXAP216 = $IXAP214[$IXAP78]; $IXAP81 = __( $IXAP216['title'], $IXAP216['domain'] ); $IXAP87 = $IXAP216['value']; $IXAP215 .= '<div class="referral-data-title">'; $IXAP215 .= stripslashes( wp_filter_nohtml_kses( $IXAP81 ) ); $IXAP215 .= '</div>'; $IXAP215 .= '<div class="referral-data-value">'; $IXAP215 .= stripslashes( wp_filter_nohtml_kses( $IXAP87 ) ); $IXAP215 .= '</div>'; } } } else { if ( !empty( $IXAP210 ) && ( $IXAP210[0] == 'data' ) ) { $IXAP215 .= '<div class="referral-data-value">'; $IXAP215 .= stripslashes( wp_filter_nohtml_kses( $IXAP214 ) ); $IXAP215 .= '</div>'; } } $IXAP62 .= apply_filters( 'affiliates_affiliate_stats_renderer_data_output', $IXAP215, $IXAP15 ); } $IXAP62 .= '</td>'; } break; default : $IXAP62 .= sprintf( '<td class="%s">', esc_attr( $IXAP78 ) ); $IXAP62 .= apply_filters( 'affiliates_affiliate_stats_renderer_column_output', '', $IXAP78, $IXAP15 ); $IXAP62 .= '</td>'; } } $IXAP62 .= '</tr>'; } } else { $IXAP62 .= '<tr><td colspan="' . $IXAP207 . '">' . __('There are no results.', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</td></tr>'; } $IXAP62 .= '</tbody>'; $IXAP62 .= '</table>'; if ( $IXAP199 ) { $IXAP200 = new Affiliates_Pagination( $IXAP198, null, $IXAP187 ); $IXAP62 .= '<div class="tablenav bottom">'; $IXAP62 .= $IXAP200->pagination( 'bottom' ); $IXAP62 .= '</div>'; } $IXAP62 .= '<div class="filters">' . '<label class="description" for="setfilters">' . __( 'Filters', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</label>' . '<form id="setfilters" action="" method="post">' . '<div class="from-date">' . '<label class="from-date-filter" for="from_date">' . __('From', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</label>' . '<input class="datefield from-date-filter" name="from_date" type="text" value="' . esc_attr( $IXAP36 ) . '"/>'. '</div>' . '<div class="thru-date">' . '<label class="thru-date-filter" for="thru_date">' . __('Until', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</label>' . '<input class="datefield thru-date-filter" name="thru_date" type="text" class="datefield" value="' . esc_attr( $IXAP38 ) . '"/>'. '</div>' . '<div class="submit">' . wp_nonce_field( plugin_basename( __FILE__ ), self::IXAP186, true, false ) . '<input type="submit" value="' . __( 'Apply', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '"/>' . '<input type="submit" name="clear_filters" value="' . __( 'Clear', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '"/>' . '<input type="hidden" value="submitted" name="submitted"/>' . '</div>' . '</form>' . '</div>'; $IXAP62 .= '</div>'; return $IXAP62; } }