class-affiliates-referral-wordpress.php
9.87 KB
<?php
class Affiliates_Referral_WordPress extends Affiliates_Referral { public function suggest( $post_id, $IXAP249 = '', $IXAP214 = null, $IXAP28 = null, $IXAP42 = null, $IXAP250 = null ) { trigger_error( __FUNCTION__ . " is deprecated", E_USER_WARNING ); return $this->evaluate( $post_id, $IXAP249, $IXAP214, null, $IXAP28, $IXAP42, $IXAP250 ); } public function evaluate( $post_id, $IXAP249 = '', $IXAP214 = null, $IXAP251 = null, $IXAP28 = null, $IXAP42 = null, $IXAP250 = null, $IXAP252 = null, $IXAP253 = null, $IXAP254 = false ) { require_once( AFFILIATES_CORE_LIB . '/class-affiliates-service.php' ); $IXAP24 = Affiliates_Service::get_referrer_id(); if ( !$IXAP254 ) { if ( $IXAP24 ) { $IXAP255 = array ( $IXAP24 ); $this->add_referrals( $IXAP255, $post_id, $IXAP249, $IXAP214, $IXAP251, $IXAP28, $IXAP42, $IXAP250, $IXAP252, $IXAP253 ); } } return $IXAP24; } public function suggest_by_attribute( $IXAP256, $IXAP257, $post_id, $IXAP249 = '', $IXAP214 = null, $IXAP251 = null, $IXAP28 = null, $IXAP42 = null, $IXAP250 = null, $IXAP252 = null, $IXAP253 = null, $IXAP254 = false ) { global $wpdb, $affiliates_options; global $affiliates_db; bcscale( AFFILIATES_REFERRAL_AMOUNT_DECIMALS ); $IXAP47 = $affiliates_db->get_tablename( "affiliates" ); $IXAP25 = $affiliates_db->get_tablename( "affiliates_attributes" ); $IXAP56 = date( 'Y-m-d H:i:s', time() ); $IXAP101 = date( 'Y-m-d', time() ); $IXAP255 = $affiliates_db->get_objects( "SELECT a.affiliate_id FROM $IXAP47 a
LEFT JOIN $IXAP25 aa ON a.affiliate_id = aa.affiliate_id
WHERE
aa.attr_key = %s
AND aa.attr_value = %s
AND a.from_date <= %s AND ( a.thru_date IS NULL OR a.thru_date >= %s )
AND a.status = 'active'
", $IXAP256, $IXAP257, $IXAP101, $IXAP101 ); if ( empty( $IXAP255 ) ) { if ( get_option( 'aff_use_direct', true ) ) { $IXAP255 = array ( (object) array( 'affiliate_id' => affiliates_get_direct_id() ) ); } } if ( !$IXAP254 ) { $IXAP258 = array(); foreach ( $IXAP255 as $IXAP24 ) { $IXAP258[] = $IXAP24->affiliate_id; } $this->add_referrals( $IXAP258, $post_id, $IXAP249, $IXAP214, $IXAP251, $IXAP28, $IXAP42, $IXAP250, $IXAP252, $IXAP253, $IXAP254 ); } return $IXAP255; } public function add_referrals( $IXAP255, $post_id, $IXAP249 = '', $IXAP214 = null, $IXAP251 = null, $IXAP28 = null, $IXAP42 = null, $IXAP250 = null, $IXAP252 = null, $IXAP253 = null, $IXAP254 = false ) { global $affiliates_db; $IXAP47 = $affiliates_db->get_tablename( "affiliates" ); $IXAP25 = $affiliates_db->get_tablename( "affiliates_attributes" ); $IXAP56 = date( 'Y-m-d H:i:s', time() ); $IXAP101 = date( 'Y-m-d', time() ); bcscale( AFFILIATES_REFERRAL_AMOUNT_DECIMALS ); if ( !empty( $IXAP255 ) ) { foreach ( $IXAP255 as $IXAP24 ) { $IXAP259 = wp_get_current_user(); $IXAP56 = date('Y-m-d H:i:s', time() ); $IXAP260 = $affiliates_db->get_tablename( 'referrals' ); $IXAP261 = "(affiliate_id, post_id, datetime, description"; $IXAP262 = "(%d, %d, %s, %s"; $IXAP90 = array($IXAP24, $post_id, $IXAP56, $IXAP249); if ( !empty( $IXAP259 ) ) { $IXAP261 .= ",user_id "; $IXAP262 .= ",%d "; $IXAP90[] = $IXAP259->ID; } $IXAP263 = $_SERVER['REMOTE_ADDR']; if ( PHP_INT_SIZE >= 8 ) { if ( $IXAP264 = ip2long( $IXAP263 ) ) { $IXAP261 .= ',ip '; $IXAP262 .= ',%d '; $IXAP90[] = $IXAP264; } } else { if ( $IXAP264 = ip2long( $IXAP263 ) ) { $IXAP264 = sprintf( '%u', $IXAP264 ); $IXAP261 .= ',ip'; $IXAP262 .= ',%s'; $IXAP90[] = $IXAP264; } } if ( !empty( $IXAP42 ) ) { if ( empty( $IXAP28 ) ) { $IXAP265 = $affiliates_db->get_objects( "SELECT * FROM $IXAP25
WHERE
affiliate_id = %d
AND attr_key IN ('referral.rate','referral.rate.method','referral.amount','referral.amount.method')
", $IXAP24 ); $IXAP266 = null; $IXAP267 = null; $IXAP268 = null; foreach( $IXAP265 as $IXAP269 ) { switch( $IXAP269->attr_key ) { case 'referral.amount' : $IXAP266 = bcadd( "0", $IXAP269->attr_value ); break; case 'referral.amount.method' : $IXAP267 = bcadd( "0", call_user_func( Affiliates_Referral::get_referral_amount_method( $IXAP269->attr_value ), $IXAP24, array( "affiliate_ids" => $IXAP255, "post_id" => $post_id, "description" => $IXAP249, "data" => $IXAP214, "base_amount" => $IXAP251, "amount" => $IXAP28, "currency_id" => $IXAP42, "status" => $IXAP250, "type" => $IXAP252, "reference" => $IXAP253, "test" => $IXAP254 ) ) ); break; case 'referral.rate' : $IXAP268 = bcmul( $IXAP251, $IXAP269->attr_value ); break; } } if ( $IXAP266 ) { $IXAP28 = $IXAP266; } else if ( $IXAP267 ) { $IXAP28 = $IXAP267; } else if ( $IXAP268 ) { $IXAP28 = $IXAP268; } else { if ( $IXAP270 = Affiliates_Attributes::validate_key( get_option( self::IXAP13, null ) ) ) { if ( $IXAP271 = Affiliates_Attributes::validate_value( $IXAP270, get_option( self::IXAP14, null ) ) ) { switch ( $IXAP270 ) { case 'referral.amount' : $IXAP28 = bcadd( "0", $IXAP271 ); break; case 'referral.amount.method' : $IXAP28 = bcadd( "0", call_user_func( Affiliates_Referral::get_referral_amount_method( $IXAP271 ), $IXAP24, array( "affiliate_ids" => $IXAP255, "post_id" => $post_id, "description" => $IXAP249, "data" => $IXAP214, "base_amount" => $IXAP251, "amount" => $IXAP28, "currency_id" => $IXAP42, "status" => $IXAP250, "type" => $IXAP252, "reference" => $IXAP253, "test" => $IXAP254 ) ) ); break; case 'referral.rate' : $IXAP28 = bcmul( $IXAP251, $IXAP271 ); break; } } } } } if ( !empty( $IXAP28 ) ) { if ( $IXAP28 = Affiliates_Utility::verify_referral_amount( $IXAP28 ) ) { if ( $IXAP42 = Affiliates_Utility::verify_currency_id( $IXAP42 ) ) { $IXAP261 .= ",amount "; $IXAP262 .= ",%s "; $IXAP90[] = $IXAP28; $IXAP261 .= ",currency_id "; $IXAP262 .= ",%s "; $IXAP90[] = $IXAP42; } } } } if ( is_array( $IXAP214 ) && !empty( $IXAP214 ) ) { $IXAP261 .= ",data "; $IXAP262 .= ",%s "; $IXAP90[] = serialize( $IXAP214 ); } if ( !empty( $IXAP250 ) && Affiliates_Utility::verify_referral_status_transition( $IXAP250, $IXAP250 ) ) { $IXAP261 .= ',status '; $IXAP262 .= ',%s '; $IXAP90[] = $IXAP250; } else { $IXAP261 .= ',status '; $IXAP262 .= ',%s '; $IXAP90[] = get_option( 'aff_default_referral_status', AFFILIATES_REFERRAL_STATUS_ACCEPTED ); } if ( !empty( $IXAP252 ) ) { $IXAP261 .= ',type '; $IXAP262 .= ',%s '; $IXAP90[] = $IXAP252; } if ( !empty( $IXAP253 ) ) { $IXAP261 .= ',reference '; $IXAP262 .= ',%s '; $IXAP90[] = $IXAP253; } $IXAP164 = null; require_once( AFFILIATES_CORE_LIB . '/class-affiliates-service.php' ); if ( $IXAP272 = Affiliates_Service::get_ids() ) { if ( !empty( $IXAP272['affiliate_id'] ) && !empty( $IXAP272['campaign_id'] ) ) { if ( $IXAP272['affiliate_id'] == $IXAP24 ) { $IXAP261 .= ',campaign_id '; $IXAP262 .= ',%d '; $IXAP164 = intval( $IXAP272['campaign_id'] ); $IXAP90[] = $IXAP164; } } } $IXAP261 .= ")"; $IXAP262 .= ")"; if ( !$IXAP254 ) { $IXAP273 = explode( ',', str_replace( ' ', '', substr( $IXAP261, 1, strlen( $IXAP261 ) - 2 ) ) ); $IXAP274 = array_combine( $IXAP273, $IXAP90 ); $IXAP275 = apply_filters( 'affiliates_record_referral', true, $IXAP274 ); if ( $IXAP275 ) { if ( !affiliates_is_duplicate_referral( array( 'affiliate_id' => $IXAP24, 'amount' => $IXAP28, 'currency_id' => $IXAP42, 'type' => $IXAP252, 'reference' => $IXAP253, 'data' => $IXAP214 ) ) ) { if ( $affiliates_db->query( "INSERT INTO $IXAP260 $IXAP261 VALUES $IXAP262", $IXAP90 ) !== false ) { if ( $IXAP276 = $affiliates_db->get_value( "SELECT LAST_INSERT_ID()" ) ) { do_action( 'affiliates_referral', $IXAP276, array( 'affiliate_id' => $IXAP24, 'post_id' => $post_id, 'description' => $IXAP249, 'data' => $IXAP214, 'base_amount' => $IXAP251, 'amount' => $IXAP28, 'currency_id' => $IXAP42, 'status' => $IXAP250, 'type' => $IXAP252, 'reference' => $IXAP253, 'test' => $IXAP254, 'campaign_id' => $IXAP164 ) ); } } } } } } } return $IXAP255; } public function __construct( $IXAP276 = null ) { if ( $IXAP276 !== null ) { global $affiliates_db; $IXAP49 = $affiliates_db->get_tablename( 'referrals' ); if ( $IXAP225 = $affiliates_db->get_objects( "SELECT * FROM $IXAP49 WHERE referral_id = %d", $IXAP276 ) ) { if ( count( $IXAP225 ) > 0 ) { $this->referral = $IXAP225[0]; } } if ( $this->referral === null ) { throw new Exception(); } } } public function update( $IXAP277 ) { global $affiliates_db; $IXAP15 = null; if ( $this->referral !== null ) { $IXAP278 = array(); $IXAP273 = array(); $IXAP90 = array(); $IXAP279 = array(); foreach( $IXAP277 as $IXAP78 => $IXAP87 ) { $IXAP280 = isset( $this->referral->$IXAP78 ) ? $this->referral->$IXAP78 : null; if ( $IXAP280 !== $IXAP87 ) { switch( $IXAP78 ) { case 'affiliate_id' : case 'post_id' : $IXAP278[] = " $IXAP78 = %d "; $IXAP273[] = $IXAP78; $IXAP90[] = intval( $IXAP87 ); $IXAP279[] = $IXAP280; break; case 'datetime' : case 'description' : case 'reference' : $IXAP278[] = " $IXAP78 = %s "; $IXAP273[] = $IXAP78; $IXAP90[] = $IXAP87; $IXAP279[] = $IXAP280; break; case 'status' : if ( !empty( $IXAP87 ) && Affiliates_Utility::verify_referral_status_transition( $IXAP87, $IXAP87 ) ) { $IXAP278[] = " $IXAP78 = %s "; $IXAP273[] = $IXAP78; $IXAP90[] = $IXAP87; $IXAP279[] = $IXAP280; } break; case 'amount' : if ( $IXAP87 = Affiliates_Utility::verify_referral_amount( $IXAP87 ) ) { $IXAP278[] = " $IXAP78 = %s "; $IXAP273[] = $IXAP78; $IXAP90[] = $IXAP87; $IXAP279[] = $IXAP280; } break; case 'currency_id' : if ( $IXAP87 = Affiliates_Utility::verify_currency_id( $IXAP87 ) ) { $IXAP278[] = " $IXAP78 = %s "; $IXAP273[] = $IXAP78; $IXAP90[] = $IXAP87; $IXAP279[] = $IXAP280; } break; } } } if ( count( $IXAP278 ) > 0 ) { $IXAP278 = implode( ' , ', $IXAP278 ); $IXAP49 = $affiliates_db->get_tablename( 'referrals' ); if ( $affiliates_db->query( "UPDATE $IXAP49 SET $IXAP278 WHERE referral_id = %d", array_merge( $IXAP90, array( intval( $this->referral->referral_id ) ) ) ) ) { if ( $IXAP225 = $affiliates_db->get_objects( "SELECT * FROM $IXAP49 WHERE referral_id = %d", intval( $this->referral->referral_id ) ) ) { if ( count( $IXAP225 ) > 0 ) { $this->referral = $IXAP225[0]; } } $IXAP15 = array( 'keys' => $IXAP273, 'values' => $IXAP90, 'old_values' => $IXAP279 ); do_action( 'affiliates_updated_referral', intval( $this->referral->referral_id ), $IXAP273, $IXAP90, $IXAP279 ); } } } return $IXAP15; } }