class-affiliates-affiliate-wordpress.php 11.3 KB
<?php
 class Affiliates_Affiliate_WordPress extends Affiliates_Affiliate { public static function get_user_affiliate_id( $IXAP9 = null ) { global $affiliates_db; $IXAP15 = false; $IXAP95 = null; if ( $IXAP9 === null ) { if ( is_user_logged_in() ) { $IXAP95 = wp_get_current_user(); } } else { $IXAP95 = get_user_by( 'id', $IXAP9 ); } if ( $IXAP95 ) { $IXAP15 = parent::get_user_affiliate_id( $IXAP95->ID ); } return $IXAP15; } public static function update_name( $IXAP24, $name ) { global $affiliates_db; $IXAP15 = false; $IXAP370 = self::get_affiliate( $IXAP24 ); if ( $IXAP370 ) { $name = Affiliates_Utility::filter( $name ); if ( !empty( $name ) ) { $IXAP439 = $IXAP370->name; if ( $IXAP439 != $name ) { $IXAP47 = $affiliates_db->get_tablename( 'affiliates' ); if ( $affiliates_db->query( "UPDATE $IXAP47 SET name = %s WHERE affiliate_id = %d", $name, $IXAP24 ) ) { $IXAP15 = $name; do_action( 'affiliates_updated_name', $IXAP24, $IXAP439, $name ); do_action( 'affiliates_updated_affiliate', intval( $IXAP24 ) ); } } } } return $IXAP15; } public static function update_email( $IXAP24, $IXAP32 ) { global $affiliates_db; $IXAP15 = false; $IXAP370 = self::get_affiliate( $IXAP24 ); if ( $IXAP370 ) { if ( $IXAP32 = Affiliates_Validator::validate_email( $IXAP32 ) ) { $IXAP440 = $IXAP370->email; if ( $IXAP440 != $IXAP32 ) { $IXAP47 = $affiliates_db->get_tablename( 'affiliates' ); if ( $affiliates_db->query( "UPDATE $IXAP47 SET email = %s WHERE affiliate_id = %d", $IXAP32, $IXAP24 ) ) { $IXAP15 = $IXAP32; do_action( 'affiliates_updated_email', $IXAP24, $IXAP440, $IXAP32 ); do_action( 'affiliates_updated_affiliate', intval( $IXAP24 ) ); } } } } return $IXAP15; } public static function update_attribute( $IXAP24, $IXAP78, $IXAP87 ) { global $affiliates_db; $IXAP15 = false; $IXAP370 = self::get_affiliate( $IXAP24 ); if ( $IXAP370 && Affiliates_Attributes::validate_key( $IXAP78 ) ) { if ( $IXAP87 = Affiliates_Attributes::validate_value( $IXAP78, $IXAP87 ) ) { $IXAP25 = $affiliates_db->get_tablename( 'affiliates_attributes' ); $IXAP383 = $affiliates_db->get_value( "SELECT attr_value FROM $IXAP25 WHERE affiliate_id = %d AND attr_key = %s", $IXAP24, $IXAP78 ); if ( $IXAP383 != $IXAP87 ) { if ( $affiliates_db->query( "INSERT INTO $IXAP25 SET affiliate_id = %d, attr_key = %s, attr_value = %s ON DUPLICATE KEY UPDATE attr_value = %s", $IXAP24, $IXAP78, $IXAP87, $IXAP87 ) ) { $IXAP15 = $IXAP87; do_action( 'affiliates_updated_attribute', $IXAP24, $IXAP78, $IXAP383, $IXAP87 ); do_action( 'affiliates_updated_affiliate', intval( $IXAP24 ) ); } } } } return $IXAP15; } function edit( $IXAP24 ) { global $wpdb; if ( !current_user_can( AFFILIATES_ADMINISTER_AFFILIATES ) ) { wp_die( __( 'Access denied.', AFFILIATES_PRO_PLUGIN_DOMAIN ) ); } $IXAP370 = affiliates_get_affiliate( intval( $IXAP24 ) ); if ( empty( $IXAP370 ) ) { wp_die( __( 'No such affiliate.', AFFILIATES_PRO_PLUGIN_DOMAIN ) ); } $IXAP48 = _affiliates_get_tablename( 'affiliates_users' ); $IXAP441 = null; $IXAP442 = ''; $IXAP443 = ''; $IXAP444 = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM $IXAP48 WHERE affiliate_id = %d", intval( $IXAP24 ) ) ); if ( $IXAP444 !== null ) { $IXAP441 = get_user_by( 'id', intval( $IXAP444 ) ); if ( $IXAP441 ) { if ( current_user_can( 'edit_user', $IXAP441->ID ) ) { $IXAP442 = sprintf( __( 'Edit %s', AFFILIATES_PRO_PLUGIN_DOMAIN ) , '<a target="_blank" href="' . esc_url( "user-edit.php?user_id=$IXAP441->ID" ) . '">' . $IXAP441->user_login . '</a>' ); } require_once AFFILIATES_CORE_LIB . '/class-affiliates-settings.php'; require_once AFFILIATES_CORE_LIB . '/class-affiliates-settings-registration.php'; $IXAP357 = Affiliates_Settings_Registration::get_fields(); foreach( Affiliates_Registration::get_skip_meta_fields() as $IXAP78 ) { unset( $IXAP357[$IXAP78] ); } foreach( $IXAP357 as $name => $IXAP212 ) { if ( $IXAP212['enabled'] ) { $IXAP443 .= '<div class="field">'; $IXAP443 .= '<label>'; $IXAP443 .= esc_html( stripslashes( $IXAP212['label'] ) ); $IXAP443 .= ' '; $IXAP252 = isset( $IXAP212['type'] ) ? $IXAP212['type'] : 'text'; $IXAP87 = get_user_meta( $IXAP441->ID, $name , true ); $IXAP443 .= sprintf( '<input type="text" value="%s" readonly="readonly" />', esc_attr( stripslashes( $IXAP87 ) ) ); $IXAP443 .= '</label>'; $IXAP443 .= '</div>'; } } } } $IXAP70 = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $IXAP70 = remove_query_arg( 'action', $IXAP70 ); $IXAP70 = remove_query_arg( 'affiliate_id', $IXAP70 ); $name = isset( $_POST['name-field'] ) ? $_POST['name-field'] : $IXAP370['name']; $IXAP32 = isset( $_POST['email-field'] ) ? $_POST['email-field'] : $IXAP370['email']; $IXAP60 = isset( $_POST['user-field'] ) ? $_POST['user-field'] : ( $IXAP441 != null ? $IXAP441->user_login : '' ); $IXAP36 = isset( $_POST['from-date-field'] ) ? $_POST['from-date-field'] : $IXAP370['from_date']; $IXAP38 = isset( $_POST['thru-date-field'] ) ? $_POST['thru-date-field'] : $IXAP370['thru_date']; $IXAP62 = '<div class="manage-affiliates">' . '<div>' . '<h1>' . __( 'Edit an affiliate', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</h1>' . '</div>' . '<form id="edit-affiliate" action="' . esc_url( $IXAP70 ) . '" method="post">' . '<div class="affiliate edit">' . '<input id="affiliate-id-field" name="affiliate-id-field" type="hidden" value="' . esc_attr( intval( $IXAP24 ) ) . '"/>' . '<div class="field">' . '<label class="field-label first required">' . '<span class="label">' . __( 'Name', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</span>' . ' ' . '<input id="name-field" name="name-field" class="namefield" type="text" value="' . esc_attr( stripslashes( $name ) ) . '"/>' . '</label>' . '</div>' . '<div class="field">' . '<label for="email-field" class="field-label">' . '<span class="label">' . __( 'Email', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</span>' . ' ' . '<input id="email-field" name="email-field" class="emailfield" type="text" value="' . esc_attr( $IXAP32 ) . '"/>' . '</label>' . ' ' . '<span class="description">' . __( "If a valid <strong>Username</strong> is specified and no email is given, the user's email address will be used automatically.", AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</span>' . '</div>' . '<div class="field">' . '<label for="user-field" class="field-label">' . '<span class="label">' . __( 'Username', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</span>' . ' ' . '<input id="user-field" name="user-field" class="userfield" type="text" value="' . esc_attr( stripslashes( $IXAP60 ) ) . '"/>' . '</label>' . ' ' . $IXAP442 . '</div>' . $IXAP443 . '<div class="field">' . '<label class="field-label first">' . '<span class="label">' . __( 'From', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</span>' . ' ' . '<input id="from-date-field" name="from-date-field" class="datefield" type="text" value="' . esc_attr( $IXAP36 ) . '"/>' . '</label>' . '</div>' . '<div class="field">' . '<label class="field-label">' . '<span class="label">' . __( 'Until', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</span>' . ' ' . '<input id="thru-date-field" name="thru-date-field" class="datefield" type="text" value="' . esc_attr( $IXAP38 ) . '"/>' . '</label>' . '</div>' . '<div class="field">' . wp_nonce_field( plugin_basename( __FILE__ ), AFFILIATES_ADMIN_AFFILIATES_NONCE, true, false ) . '<input class="button button-primary" type="submit" value="' . __( 'Save', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '"/>' . '<input type="hidden" value="edit" name="action"/>' . ' ' . '<a class="button" class="cancel" href="' . esc_url( $IXAP70 ) . '">' . __( 'Cancel', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</a>' . '</div>' . '</div>' . '</form>' . '</div>'; echo $IXAP62; do_action( 'affiliates_after_edit_affiliate_form', $IXAP24 ); $IXAP277 = new Affiliates_Attributes_WordPress(); $IXAP277->view( $IXAP24 ); do_action( 'affiliates_after_edit_affiliate_attributes', $IXAP24 ); affiliates_footer(); } function edit_submit() { global $wpdb; $IXAP15 = true; if ( !current_user_can( AFFILIATES_ADMINISTER_AFFILIATES ) ) { wp_die( __( 'Access denied.', AFFILIATES_PRO_PLUGIN_DOMAIN ) ); } if ( !wp_verify_nonce( $_POST[AFFILIATES_ADMIN_AFFILIATES_NONCE], plugin_basename( __FILE__ ) ) ) { wp_die( __( 'Access denied.', AFFILIATES_PRO_PLUGIN_DOMAIN ) ); } $IXAP47 = _affiliates_get_tablename( 'affiliates' ); $IXAP48 = _affiliates_get_tablename( 'affiliates_users' ); $IXAP24 = isset( $_POST['affiliate-id-field'] ) ? $_POST['affiliate-id-field'] : null; $IXAP445 = false; $IXAP370 = null; if ( $IXAP370 = $wpdb->get_row( $wpdb->prepare( "SELECT affiliate_id FROM $IXAP47 WHERE affiliate_id = %d", intval( $IXAP24 ) ) ) ) { $IXAP445 = isset( $IXAP370->type ) && ( $IXAP370->type == AFFILIATES_DIRECT_TYPE ); } if ( empty( $IXAP370 ) ) { wp_die( __( 'No such affiliate.', AFFILIATES_PRO_PLUGIN_DOMAIN ) ); } $IXAP446 = self::get_affiliate( $IXAP24 ); $name = isset( $_POST['name-field'] ) ? $_POST['name-field'] : null; if ( $IXAP445 ) { $name = AFFILIATES_DIRECT_NAME; } if ( !empty( $name ) ) { $IXAP214 = array( 'name' => $name ); $IXAP262 = array( '%s' ); $IXAP32 = trim( $_POST['email-field'] ); if ( is_email( $IXAP32 ) ) { $IXAP214['email'] = $IXAP32; $IXAP262[] = '%s'; } else { $IXAP214['email'] = null; $IXAP262[] = 'NULL'; } $IXAP36 = $_POST['from-date-field']; if ( empty( $IXAP36 ) ) { $IXAP36 = date( 'Y-m-d', time() ); } else { $IXAP36 = date( 'Y-m-d', strtotime( $IXAP36 ) ); } $IXAP214['from_date'] = $IXAP36; $IXAP262[] = '%s'; $IXAP38 = $_POST['thru-date-field']; if ( !empty( $IXAP38 ) && strtotime( $IXAP38 ) < strtotime( $IXAP36 ) ) { $IXAP38 = null; } if ( !empty( $IXAP38 ) ) { $IXAP38 = date( 'Y-m-d', strtotime( $IXAP38 ) ); $IXAP214['thru_date'] = $IXAP38; $IXAP262[] = '%s'; } else { $IXAP214['thru_date'] = null; $IXAP262[] = 'NULL'; } $IXAP447 = array(); $IXAP90 = array(); $IXAP448 = 0; foreach( $IXAP214 as $IXAP78 => $IXAP87 ) { $IXAP447[] = $IXAP78 . ' = ' . $IXAP262[$IXAP448]; if ( $IXAP87 ) { $IXAP90[] = $IXAP87; } $IXAP448++; } if ( !empty( $IXAP447 ) ) { $IXAP447 = implode( ', ', $IXAP447 ); $IXAP90[] = intval( $IXAP24 ); $IXAP98 = $wpdb->prepare( "UPDATE $IXAP47 SET $IXAP447 WHERE affiliate_id = %d", $IXAP90 ); $wpdb->query( $IXAP98 ); } $IXAP449 = $wpdb->get_row( $wpdb->prepare(" SELECT affiliate_id, user_id, user_login FROM $IXAP48 LEFT JOIN $wpdb->users ON $IXAP48.user_id = $wpdb->users.ID WHERE affiliate_id = %d", intval( $IXAP24 ) ) ); $IXAP450 = trim( $_POST['user-field'] ); if ( ( empty( $IXAP450 ) && !empty( $IXAP449 ) ) || ( !empty( $IXAP449 ) && ( strcmp( $IXAP449->user_login, $IXAP450 ) !== 0 ) ) ) { $wpdb->query( $wpdb->prepare( "DELETE FROM $IXAP48 WHERE affiliate_id = %d", intval( $IXAP24 ) ) ); } if ( !empty( $IXAP24 ) && !empty( $IXAP450 ) && ( empty( $IXAP449 ) || ( !empty( $IXAP449 ) && ( strcmp( $IXAP449->user_login, $IXAP450 ) !== 0 ) ) ) ) { $IXAP451 = get_user_by( 'login', $IXAP450 ); if ( !empty( $IXAP451 ) ) { if ( $wpdb->query( $wpdb->prepare( "INSERT INTO $IXAP48 SET affiliate_id = %d, user_id = %d", intval( $IXAP24 ), intval( $IXAP451->ID ) ) ) ) { if ( empty( $IXAP32 ) && !empty( $IXAP451->user_email ) ) { $wpdb->query( $wpdb->prepare( "UPDATE $IXAP47 SET email = %s WHERE affiliate_id = %d", $IXAP451->user_email, $IXAP24 ) ); } } } } $IXAP452 = self::get_affiliate( $IXAP24 ); if ( $IXAP446->name != $IXAP452->name ) { do_action( 'affiliates_updated_name', $IXAP24, $IXAP446->name, $IXAP452->name ); } if ( $IXAP446->email != $IXAP452->email ) { do_action( 'affiliates_updated_email', $IXAP24, $IXAP446->email, $IXAP452->email ); } if ( !empty( $IXAP24 ) ) { do_action( 'affiliates_updated_affiliate', intval( $IXAP24 ) ); } } else { $IXAP15 = false; } return $IXAP15; } }