class-affiliates-stats-renderer-wordpress.php 9.7 KB
<?php
 class Affiliates_Stats_Renderer_WordPress extends Affiliates_Stats_Renderer { const IXAP183 = 'affiliate-nonce'; const IXAP184 = 'affiliate-nonce-1'; const IXAP185 = 'affiliate-nonce-2'; const IXAP186 = 'affiliate-nonce-filters'; static function init() { add_shortcode( 'affiliates_affiliate_stats', array( 'Affiliates_Stats_Renderer_WordPress', 'stats_shortcode' ) ); } static function stats_shortcode( $IXAP223, $IXAP167 = null ) { $IXAP15 = null; wp_enqueue_script( 'datepicker' ); wp_enqueue_script( 'datepickers' ); wp_enqueue_style( 'smoothness' ); wp_enqueue_style( 'affiliates-pro' ); $IXAP105 = shortcode_atts( self::$IXAP181, $IXAP223 ); switch ( $IXAP105['type'] ) { case self::IXAP224 : $IXAP15 = Affiliates_Affiliate_Stats_Renderer_WordPress::render_referrals( $IXAP105 ); break; case self::IXAP182 : $IXAP15 = self::render_affiliate_stats( $IXAP105 ); break; } return $IXAP15; } static function render_affiliate_stats( $IXAP105 = array() ) { global $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_from_date', null ); $IXAP38 = $affiliates_options->get_option( 'affiliate_stats_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_from_date' ); $affiliates_options->delete_option( 'affiliate_stats_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_from_date', $IXAP36 ); } if ( !empty( $_POST['thru_date'] ) ) { $IXAP38 = date( 'Y-m-d', strtotime( $_POST['thru_date'] ) ); $affiliates_options->update_option( 'affiliate_stats_thru_date', $IXAP38 ); } if ( $IXAP36 && $IXAP38 ) { if ( strtotime( $IXAP36 ) > strtotime( $IXAP38 ) ) { $IXAP38 = null; $affiliates_options->delete_option( 'affiliate_stats_thru_date' ); } } } } if ( $IXAP36 ) { $IXAP37 = DateHelper::u2s( $IXAP36 ); } if ( $IXAP38 ) { $IXAP39 = DateHelper::u2s( $IXAP38, 24*3600 ); } $IXAP47 = $affiliates_db->get_tablename( 'affiliates' ); $IXAP49 = $affiliates_db->get_tablename( 'referrals' ); $IXAP112 = $affiliates_db->get_tablename( 'hits' ); 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 .= " h.affiliate_id = %d "; $IXAP52[] = $IXAP24; } $IXAP76 = array( 'visits' => __( 'Visits', AFFILIATES_PRO_PLUGIN_DOMAIN ), 'hits' => __( 'Hits', AFFILIATES_PRO_PLUGIN_DOMAIN ), 'referrals' => __( 'Referrals', AFFILIATES_PRO_PLUGIN_DOMAIN ), 'ratio' => __( 'Ratio', AFFILIATES_PRO_PLUGIN_DOMAIN ) ); $IXAP117 = affiliates_get_affiliate_visits( $IXAP24, $IXAP36, $IXAP38 ); $IXAP114 = affiliates_get_affiliate_hits( $IXAP24, $IXAP36, $IXAP38 ); $IXAP225 = affiliates_get_affiliate_referrals( $IXAP24, $IXAP36, $IXAP38 ); if ( $IXAP117 > 0 ) { $IXAP226 = round( $IXAP225 / $IXAP117, self::IXAP227 ); } else { $IXAP226 = 0; } $IXAP62 .= '<div id="" class="affiliate-stats summary">'; $IXAP62 .= '
			<table class="wp-list-table widefat fixed" cellspacing="0">
			<thead>
				<tr>
				'; foreach ( $IXAP76 as $IXAP78 => $IXAP79 ) { $IXAP62 .= "<th scope='col' class='$IXAP78'>$IXAP79</th>"; } $IXAP62 .= '</tr>
			</thead>
			<tbody>
			'; $IXAP62 .= '<tr>'; $IXAP62 .= "<td class='visits'>$IXAP117</td>"; $IXAP62 .= "<td class='hits'>$IXAP114</td>"; $IXAP62 .= "<td class='referrals'>$IXAP225</td>"; $IXAP62 .= "<td class='ratio'>$IXAP226</td>"; $IXAP62 .= '</tr>'; $IXAP62 .= '</tbody>'; $IXAP62 .= '</table>'; $IXAP228 = isset( $IXAP105['show_totals'] ) ? ( $IXAP105['show_totals'] !== 'false' ) : true; $IXAP229 = isset( $IXAP105['show_totals_accepted'] ) ? ( $IXAP105['show_totals_accepted'] === true || $IXAP105['show_totals_accepted'] === 'true' ) : false; $IXAP230 = isset( $IXAP105['show_totals_pending'] ) ? ( $IXAP105['show_totals_pending'] === true || $IXAP105['show_totals_pending'] === 'true' ) : false; $IXAP231 = isset( $IXAP105['show_totals_closed'] ) ? ( $IXAP105['show_totals_closed'] === true || $IXAP105['show_totals_closed'] === 'true' ) : false; $IXAP232 = isset( $IXAP105['show_totals_rejected'] ) ? ( $IXAP105['show_totals_rejected'] === true || $IXAP105['show_totals_rejected'] === 'true' ) : false; if ( $IXAP228 && ( $IXAP229 || $IXAP230 || $IXAP231 || $IXAP232 ) ) { $IXAP233 = ''; if ( $IXAP36 && $IXAP38 ) { $IXAP233 = " AND datetime >= '$IXAP37' AND datetime < '$IXAP39' "; } else if ( $IXAP36 ) { $IXAP233 = " AND datetime >= '$IXAP37' "; } else if ( $IXAP38 ) { $IXAP233 = " AND datetime < '$IXAP39' "; } $IXAP234 = $affiliates_db->get_objects( "SELECT SUM(amount) AS total, currency_id FROM $IXAP49 WHERE affiliate_id = %d $IXAP233 AND status = %s AND amount IS NOT NULL AND currency_id IS NOT NULL GROUP BY currency_id", $IXAP24, AFFILIATES_REFERRAL_STATUS_ACCEPTED ); $IXAP235 = $affiliates_db->get_objects( "SELECT SUM(amount) AS total, currency_id FROM $IXAP49 WHERE affiliate_id = %d $IXAP233 AND status = %s AND amount IS NOT NULL AND currency_id IS NOT NULL GROUP BY currency_id", $IXAP24, AFFILIATES_REFERRAL_STATUS_PENDING ); $IXAP236 = $affiliates_db->get_objects( "SELECT SUM(amount) AS total, currency_id FROM $IXAP49 WHERE affiliate_id = %d $IXAP233 AND status = %s AND amount IS NOT NULL AND currency_id IS NOT NULL GROUP BY currency_id", $IXAP24, AFFILIATES_REFERRAL_STATUS_CLOSED ); $IXAP237 = $affiliates_db->get_objects( "SELECT SUM(amount) AS total, currency_id FROM $IXAP49 WHERE affiliate_id = %d $IXAP233 AND status = %s AND amount IS NOT NULL AND currency_id IS NOT NULL GROUP BY currency_id", $IXAP24, AFFILIATES_REFERRAL_STATUS_REJECTED ); $IXAP62 .= '<table class="wp-list-table widefat fixed" cellspacing="0">'; $IXAP62 .= '<thead>'; $IXAP62 .= '<tr>'; $IXAP62 .= "<th scope='col' class='total'>" . __( 'Total', AFFILIATES_PRO_PLUGIN_DOMAIN ) . "</th>"; $IXAP62 .= "<th scope='col' class='amount'>" . __( 'Amount', AFFILIATES_PRO_PLUGIN_DOMAIN ) . "</th>"; $IXAP62 .= "<th scope='col' class='currency'>" . __( 'Currency', AFFILIATES_PRO_PLUGIN_DOMAIN ) . "</th>"; $IXAP62 .= '</tr>'; $IXAP62 .= '</thead>'; $IXAP62 .= '<tbody>'; if ( $IXAP229 ) { if ( count( $IXAP234 ) == 0 ) { $IXAP234[] = (object) array( 'total' => '--', 'currency_id' => '--' ); } foreach ( $IXAP234 as $IXAP238 ) { $IXAP62 .= '<tr>'; $IXAP62 .= "<td class='total accepted'>" . __( 'Accepted', AFFILIATES_PRO_PLUGIN_DOMAIN ) . "</td>"; $IXAP62 .= "<td class='amount'>$IXAP238->total</td>"; $IXAP62 .= "<td class='currency'>$IXAP238->currency_id</td>"; $IXAP62 .= '</tr>'; } } if ( $IXAP230 ) { if ( count( $IXAP235 ) == 0 ) { $IXAP235[] = (object) array( 'total' => '--', 'currency_id' => '--' ); } foreach ( $IXAP235 as $IXAP238 ) { $IXAP62 .= '<tr>'; $IXAP62 .= "<td class='total pending'>" . __( 'Pending', AFFILIATES_PRO_PLUGIN_DOMAIN ) . "</td>"; $IXAP62 .= "<td class='amount'>$IXAP238->total</td>"; $IXAP62 .= "<td class='currency'>$IXAP238->currency_id</td>"; $IXAP62 .= '</tr>'; } } if ( $IXAP231 ) { if ( count( $IXAP236 ) == 0 ) { $IXAP236[] = (object) array( 'total' => '--', 'currency_id' => '--' ); } foreach ( $IXAP236 as $IXAP238 ) { $IXAP62 .= '<tr>'; $IXAP62 .= "<td class='total closed'>" . __( 'Closed', AFFILIATES_PRO_PLUGIN_DOMAIN ) . "</td>"; $IXAP62 .= "<td class='amount'>$IXAP238->total</td>"; $IXAP62 .= "<td class='currency'>$IXAP238->currency_id</td>"; $IXAP62 .= '</tr>'; } } if ( $IXAP232 ) { if ( count( $IXAP237 ) == 0 ) { $IXAP237[] = (object) array( 'total' => '--', 'currency_id' => '--' ); } foreach ( $IXAP237 as $IXAP238 ) { $IXAP62 .= '<tr>'; $IXAP62 .= "<td class='total rejected'>" . __( 'Rejected', AFFILIATES_PRO_PLUGIN_DOMAIN ) . "</td>"; $IXAP62 .= "<td class='amount'>$IXAP238->total</td>"; $IXAP62 .= "<td class='currency'>$IXAP238->currency_id</td>"; $IXAP62 .= '</tr>'; } } $IXAP62 .= '</tbody>'; $IXAP62 .= '</table>'; } $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>' . '<noscript><span class="description mini">' . __( 'Format: YYYY-MM-DD', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</span></noscript>' . '<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>' . '<noscript><span class="description mini">' . __( 'Format: YYYY-MM-DD', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</span></noscript>' . '<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; } } Affiliates_Stats_Renderer_WordPress::init();