class-affiliates-affiliate-stats-widget.php 8.62 KB
<?php
 class Affiliates_Affiliate_Stats_Widget extends WP_Widget { function __construct() { parent::__construct( false, $name = 'Affiliates Affiliate Stats' ); } function widget( $args, $IXAP242 ) { if ( !affiliates_user_is_affiliate() ) { return; } extract( $args ); $IXAP81 = isset( $IXAP242['title'] ) ? apply_filters( 'widget_title', $IXAP242['title'] ) : ''; $IXAP243 = $args['widget_id']; echo $before_widget; if ( !empty( $IXAP81 ) ) { echo $before_title . $IXAP81 . $after_title; } $IXAP244 = '-' . $IXAP243; $IXAP105 = array( 'is_widget' => true ); $IXAP105 = array_merge( $IXAP105, $IXAP242 ); echo $this->render_affiliate_stats( $IXAP105, $IXAP243 ); echo $after_widget; } function update( $IXAP245, $IXAP246 ) { $IXAP247 = $IXAP246; if ( !empty( $IXAP245['title'] ) ) { $IXAP247['title'] = strip_tags( $IXAP245['title'] ); } else { unset( $IXAP247['title'] ); } $IXAP248 = array( 'show_totals_accepted', 'show_totals_pending', 'show_totals_closed', 'show_totals_rejected' ); foreach ( $IXAP248 as $IXAP238 ) { if ( !empty( $IXAP245[$IXAP238] ) ) { $IXAP247[$IXAP238] = true; } else { unset( $IXAP247[$IXAP238] ); } } return $IXAP247; } function form( $IXAP242 ) { $IXAP81 = isset( $IXAP242['title'] ) ? esc_attr( $IXAP242['title'] ) : ''; ?>
		<p>
			<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:', AFFILIATES_PRO_PLUGIN_DOMAIN ); ?></label> 
			<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $IXAP81; ?>" />
		</p>
		<?php
 $IXAP229 = isset( $IXAP242['show_totals_accepted'] ) ? $IXAP242['show_totals_accepted'] : false; echo '<input type="checkbox" ' . ( $IXAP229 ? ' checked="checked" ' : '' ) . ' name="' . $this->get_field_name( 'show_totals_accepted' ) . '" id="' . $this->get_field_id( 'show_totals_accepted' ) . '"/>'; echo '<label for="' . $this->get_field_name( 'show_totals_accepted' ) . '">' . __( 'Show totals for accepted referrals', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</label>'; echo '<br/>'; $IXAP230 = isset( $IXAP242['show_totals_pending'] ) ? $IXAP242['show_totals_pending'] : false; echo '<input type="checkbox" ' . ( $IXAP230 ? ' checked="checked" ' : '' ) . ' name="' . $this->get_field_name( 'show_totals_pending' ) . '" id="' . $this->get_field_id( 'show_totals_pending' ) . '"/>'; echo '<label for="' . $this->get_field_name( 'show_totals_pending' ) . '">' . __( 'Show totals for pending referrals', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</label>'; echo '<br/>'; $IXAP231 = isset( $IXAP242['show_totals_closed'] ) ? $IXAP242['show_totals_closed'] : false; echo '<input type="checkbox" ' . ( $IXAP231 ? ' checked="checked" ' : '' ) . ' name="' . $this->get_field_name( 'show_totals_closed' ) . '" id="' . $this->get_field_id( 'show_totals_closed' ) . '"/>'; echo '<label for="' . $this->get_field_name( 'show_totals_closed' ) . '">' . __( 'Show totals for closed referrals', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</label>'; echo '<br/>'; $IXAP232 = isset( $IXAP242['show_totals_rejected'] ) ? $IXAP242['show_totals_rejected'] : false; echo '<input type="checkbox" ' . ( $IXAP232 ? ' checked="checked" ' : '' ) . ' name="' . $this->get_field_name( 'show_totals_rejected' ) . '" id="' . $this->get_field_id( 'show_totals_rejected' ) . '"/>'; echo '<label for="' . $this->get_field_name( 'show_totals_rejected' ) . '">' . __( 'Show totals for rejected referrals', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</label>'; } public static function render_affiliate_stats( $IXAP105 = array() ) { global $affiliates_db; $IXAP62 = ''; $IXAP24 = Affiliates_Affiliate_WordPress::get_user_affiliate_id(); if ( $IXAP24 === false ) { return $IXAP62; } wp_enqueue_style( 'affiliates' ); wp_enqueue_style( 'affiliates-pro' ); $IXAP47 = $affiliates_db->get_tablename( 'affiliates' ); $IXAP49 = $affiliates_db->get_tablename( 'referrals' ); $IXAP112 = $affiliates_db->get_tablename( 'hits' ); $IXAP117 = affiliates_get_affiliate_visits( $IXAP24 ); $IXAP114 = affiliates_get_affiliate_hits( $IXAP24 ); $IXAP225 = affiliates_get_affiliate_referrals( $IXAP24 ); if ( $IXAP117 > 0 ) { $IXAP226 = round( $IXAP225 / $IXAP117, I_Affiliates_Stats_Renderer::IXAP227 ); } else { $IXAP226 = 0; } $IXAP62 .= '<div class="visits">' . sprintf( _n( '%d Visit', '%d Visits', $IXAP117, AFFILIATES_PRO_PLUGIN_DOMAIN ), $IXAP117 ) . '</div>'; $IXAP62 .= '<div class="hits">' . sprintf( _n( '%d Hit', '%d Hits', $IXAP114, AFFILIATES_PRO_PLUGIN_DOMAIN ), $IXAP114 ) . '</div>'; $IXAP62 .= '<div class="referrals">' . sprintf( _n( '%d Referral', '%d Referrals', $IXAP225, AFFILIATES_PRO_PLUGIN_DOMAIN ), $IXAP225 ) . '</div>'; $IXAP62 .= '<div class="ratio">' . sprintf( __( '%.3f Ratio', AFFILIATES_PRO_PLUGIN_DOMAIN ), $IXAP226 ) . '</div>'; $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 ) ) { $IXAP234 = $affiliates_db->get_objects( "SELECT SUM(amount) AS total, currency_id FROM $IXAP49 WHERE affiliate_id = %d 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 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 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 AND status = %s AND amount IS NOT NULL AND currency_id IS NOT NULL GROUP BY currency_id", $IXAP24, AFFILIATES_REFERRAL_STATUS_REJECTED ); $IXAP62 .= '<div class="totals">'; $IXAP62 .= '<table cellpadding="0" 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>'; } return $IXAP62; } }?>