class-affiliates-attributes-wordpress.php 19.9 KB
<?php
class Affiliates_Attributes_WordPress extends Affiliates_Attributes { function view( $IXAP24 ) { global $wpdb, $affiliates_options, $affiliates_db; $IXAP62 = ''; $IXAP369 = new Affiliates_Affiliate_WordPress(); $IXAP370 = $IXAP369->get_affiliate( $IXAP24 ); if ( $IXAP370 ) { $IXAP70 = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $IXAP70 = remove_query_arg( 'action', $IXAP70 ); $IXAP70 = remove_query_arg( 'affiliate_id', $IXAP70 ); $IXAP187 = isset( $_POST['row_count'] ) ? intval( $_POST['row_count'] ) : 0; if ($IXAP187 <= 0) { $IXAP187 = $affiliates_options->get_option( 'affiliates_attributes_per_page', AFFILIATES_HITS_PER_PAGE ); } else { $affiliates_options->update_option('affiliates_attributes_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 ( $IXAP190 < 0 ) { $IXAP190 = 0; } $IXAP62 .= '<div class="manage-affiliates">' . '<div>' . '<h2>' . __( 'Affiliate Attributes', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</h2>' . '</div>'; $IXAP62 .= '<div class="manage">' . "<a title='" . __( 'Click to add a new attribute', AFFILIATES_PRO_PLUGIN_DOMAIN ) . "' class='add' href='" . esc_url( $IXAP70 ) . "&action=add-attribute&affiliate_id=" . urlencode( $IXAP24 ) . "'><img class='icon' alt='" . __( 'Add', AFFILIATES_PRO_PLUGIN_DOMAIN) . "' src='". AFFILIATES_PRO_PLUGIN_URL ."images/add.png'/><span class='label'>" . __( 'New Attribute', AFFILIATES_PRO_PLUGIN_DOMAIN) . "</span></a>" . '</div>'; $IXAP62 .= '<div class="affiliates-attributes-overview">'; $IXAP76 = array( 'attr_key' => __( 'Id', AFFILIATES_PRO_PLUGIN_DOMAIN ), 'attr_value' => __( 'Value', AFFILIATES_PRO_PLUGIN_DOMAIN ), 'edit' => __( 'Edit', AFFILIATES_PRO_PLUGIN_DOMAIN ), 'remove' => __( 'Remove', AFFILIATES_PRO_PLUGIN_DOMAIN ) ); $IXAP62 .= '
				<table id="" 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>
				'; $IXAP25 = $affiliates_db->get_tablename( "affiliates_attributes" ); $IXAP223 = $affiliates_db->get_objects("SELECT * FROM $IXAP25 WHERE affiliate_id = %d", $IXAP24 ); if ( !empty( $IXAP223 ) ) { $IXAP273 = Affiliates_Attributes::get_keys(); $IXAP80 = 0; foreach ( $IXAP223 as $IXAP371 ) { $IXAP296 = ''; $IXAP298 = ''; $IXAP62 .= '<tr class="' . $IXAP296 . $IXAP298 . ( $IXAP80 % 2 == 0 ? 'even' : 'odd' ) . '">'; $IXAP62 .= '<td>' . wp_filter_kses( $IXAP273[$IXAP371->attr_key] ) . '</td>'; $IXAP372 = @unserialize( $IXAP371->attr_value ); if ( $IXAP372 !== false ) { $IXAP87 = $IXAP372; } else { $IXAP87 = $IXAP371->attr_value; } if ( is_array( $IXAP87 ) ) { $IXAP87 = implode( "::", $IXAP87 ); } $IXAP62 .= '<td>' . wp_filter_kses( $IXAP87 ) . '</td>'; $IXAP62 .= "<td class='edit'><a href='" . esc_url( $IXAP70 ) . "&action=edit-attribute&affiliate_id=" . urlencode( $IXAP24 ) . "&attr_key=" . urlencode( $IXAP371->attr_key ) . "' alt='" . __( 'Edit', AFFILIATES_PRO_PLUGIN_DOMAIN) . "'><img src='". AFFILIATES_PRO_PLUGIN_URL ."images/edit.png'/></a></td>"; $IXAP62 .= "<td class='remove'><a href='" . esc_url( $IXAP70 ) . "&action=remove-attribute&affiliate_id=" . urlencode( $IXAP24 ) . "&attr_key=" . urlencode( $IXAP371->attr_key ) . "' alt='" . __( 'Remove', AFFILIATES_PRO_PLUGIN_DOMAIN) . "'><img src='". AFFILIATES_PRO_PLUGIN_URL ."images/remove.png'/></a></td>"; $IXAP62 .= '</tr>'; $IXAP80++; } $IXAP62 .= '</table>'; $IXAP62 .= '</td>'; $IXAP62 .= '</tr>'; } else { $IXAP62 .= '<tr><td colspan="' . count( $IXAP76 ) . '">' . __('There are no results.', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</td></tr>'; } $IXAP62 .= '</tbody>'; $IXAP62 .= '</table>'; $IXAP62 .= '</div>'; $IXAP62 .= '</div>'; } echo $IXAP62; } function add( $IXAP24 ) { global $affiliates_db; if ( !current_user_can( AFFILIATES_ADMINISTER_AFFILIATES ) ) { wp_die( __( 'Access denied.', AFFILIATES_PRO_PLUGIN_DOMAIN ) ); } affiliates_pro_admin_notices(); $IXAP70 = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $IXAP70 = remove_query_arg( 'action', $IXAP70 ); $IXAP70 = remove_query_arg( 'affiliate_id', $IXAP70 ); $IXAP373 = esc_url( $IXAP70 ) . "&action=edit&affiliate_id=" . urlencode( $IXAP24 ); $IXAP70 = remove_query_arg( 'paged', $IXAP70 ); $IXAP24 = isset( $_POST['affiliate_id'] ) ? $_POST['affiliate_id'] : $IXAP24; $IXAP365 = isset( $_POST['attr-key-field'] ) ? $_POST['attr-key-field'] : ''; $IXAP368 = isset( $_POST['attr-value-field'] ) ? $_POST['attr-value-field'] : ''; $IXAP374 = array(); $IXAP25 = $affiliates_db->get_tablename( 'affiliates_attributes' ); $IXAP375 = $affiliates_db->get_objects( "SELECT * FROM $IXAP25 WHERE affiliate_id = %d", $IXAP24 ); foreach( $IXAP375 as $IXAP376 ) { $IXAP374[] = $IXAP376->attr_key; } $IXAP377 = '<select id="attr-key-field" name="attr-key-field" class="attr-key-field">'; $IXAP273 = Affiliates_Attributes::get_keys(); foreach( $IXAP273 as $IXAP78 => $name ) { if ( !in_array( $IXAP78, $IXAP374 ) ) { $IXAP292 = $IXAP365 == $IXAP78 ? ' selected="selected" ' : ''; $IXAP377 .= '<option value="' . esc_attr( $IXAP78 ) . '" ' . $IXAP292 . '>' . wp_filter_kses( $name ) . '</option>'; } } $IXAP377 .= '</select>'; $IXAP62 = '<div class="manage-affiliates">' . '<div>' . '<h1>' . __( 'Add a new attribute', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</h1>' . '</div>' . '<form id="add-attribute" action="' . esc_url( $IXAP70 ) . '" method="post">' . '<div class="affiliate new">' . '<div class="field">' . '<label for="attr-key-field" class="field-label first required">' .__( 'Key', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</label>' . $IXAP377 . '</div>' . '<div class="field">' . '<label for="attr-value-field" class="field-label first required">' .__( 'Value', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</label>' . '<input id="attr-value-field" name="attr-value-field" class="attr-value-field" type="text" value="' . esc_attr( $IXAP368 ) . '"/>' . '</div>' . '<div class="field">' . wp_nonce_field( plugin_basename( __FILE__ ), AFFILIATES_ADMIN_AFFILIATES_NONCE, true, false ) . '<input class="button button-primary" type="submit" value="' . __( 'Add', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '"/>' . '<input type="hidden" value="' . esc_attr( $IXAP24 ) . '" name="affiliate_id"/>' . '<input type="hidden" value="add-attribute" name="action"/>' . ' ' . '<a class="cancel button" href="' . $IXAP373 . '">' . __( 'Cancel', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</a>' . '</div>' . '</div>' . '</form>' . '</div>'; echo $IXAP62; } function add_submit() { global $wpdb, $affiliates_db, $IXAP1; $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 ) ); } $IXAP25 = $affiliates_db->get_tablename( 'affiliates_attributes' ); $IXAP24 = isset( $_POST['affiliate_id'] ) ? $_POST['affiliate_id'] : null; $IXAP365 = isset( $_POST['attr-key-field'] ) ? $_POST['attr-key-field'] : null; $IXAP368 = isset( $_POST['attr-value-field'] ) ? $_POST['attr-value-field'] : null; if ( $IXAP368 !== null ) { $IXAP368 = Affiliates_Attributes::validate_value( $IXAP365, $IXAP368 ); if ( $IXAP368 !== false ) { if ( is_array( $IXAP368 ) || is_object( $IXAP368 ) ) { $IXAP368 = serialize( $IXAP368 ); } } else { $IXAP368 = null; } } $IXAP378 = false; if ( ( $IXAP365 == Affiliates_Attributes::IXAP86 ) && !empty( $IXAP368 ) ) { $IXAP379 = explode( ",", $IXAP368 ); foreach( $IXAP379 as $IXAP380 ) { $IXAP380 = trim( $IXAP380 ); $IXAP381 = self::get_affiliate_for_coupon( $IXAP380 ); if ( ( $IXAP381 !== null ) && ( $IXAP381 != $IXAP24 ) ) { $IXAP1[] = '<div class="error">' . sprintf( __( 'Coupons may not be assigned to multiple affiliates. The coupon code <strong>%s</strong> has already been assigned to the affiliate with Id %d.', AFFILIATES_PRO_PLUGIN_DOMAIN), $IXAP380, $IXAP381 ) . '</div>'; $IXAP378 = true; } } } if ( $IXAP378 ) { return false; } if ( !empty( $IXAP24 ) && Affiliates_Attributes::validate_key( $IXAP365 ) && ( $IXAP368 !== null ) ) { if ( !$affiliates_db->get_value( "SELECT * FROM $IXAP25 WHERE affiliate_id = %d AND attr_key = %s", $IXAP24, $IXAP365 ) ) { if ( $affiliates_db->query( "INSERT INTO $IXAP25 SET affiliate_id=%d, attr_key=%s, attr_value=%s", $IXAP24, $IXAP365, $IXAP368 ) ) { do_action( 'affiliates_added_attribute', $IXAP24, $IXAP365, $IXAP368 ); } } else { $IXAP1[] = '<div class="error">' . __( 'Duplicate key', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</div>'; $IXAP15 = false; } } else { $IXAP1[] = '<div class="error">' . __( 'Invalid data', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</div>'; $IXAP15 = false; } return $IXAP15; } function edit( $IXAP24, $IXAP365 ) { global $affiliates_db; if ( !current_user_can( AFFILIATES_ADMINISTER_AFFILIATES ) ) { wp_die( __( 'Access denied.', AFFILIATES_PRO_PLUGIN_DOMAIN ) ); } affiliates_pro_admin_notices(); $IXAP70 = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $IXAP70 = remove_query_arg( 'action', $IXAP70 ); $IXAP70 = remove_query_arg( 'affiliate_id', $IXAP70 ); $IXAP373 = esc_url( $IXAP70 ) . "&action=edit&affiliate_id=" . urlencode( $IXAP24 ); $IXAP70 = remove_query_arg( 'paged', $IXAP70 ); $IXAP25 = $affiliates_db->get_tablename( 'affiliates_attributes' ); $IXAP368 = $affiliates_db->get_value( "SELECT attr_value FROM $IXAP25 WHERE affiliate_id = %d AND attr_key = %s", $IXAP24, $IXAP365 ); $IXAP24 = isset( $_POST['affiliate_id'] ) ? $_POST['affiliate_id'] : $IXAP24; $IXAP365 = isset( $_POST['attr-key-field'] ) ? $_POST['attr-key-field'] : $IXAP365; $IXAP368 = isset( $_POST['attr-value-field'] ) ? $_POST['attr-value-field'] : $IXAP368; $IXAP382 = @unserialize( $IXAP368 ); if ( $IXAP382 === false ) { $IXAP382 = $IXAP368; } if ( is_array( $IXAP382 ) ) { $IXAP382 = implode( "::", $IXAP382 ); } $IXAP273 = Affiliates_Attributes::get_keys(); $IXAP62 = '<div class="manage-affiliates">' . '<div>' . '<h1>' . __( 'Edit an attribute', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</h1>' . '</div>' . '<form id="edit-attribute" action="' . esc_url( $IXAP70 ) . '" method="post">' . '<div class="affiliate-attribute edit">' . '<div class="field">' . '<label for="attr-key-field" class="field-label first required">' .__( 'Key', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</label>' . '<input readonly="readonly" id="attr-name-field" name="attr-name-field" class="attr-name-field" type="text" value="' . esc_attr( $IXAP273[$IXAP365] ) . '"/>' . '<input type="hidden" name="attr-key-field" value="' . esc_attr( $IXAP365 ) . '"/>' . '</div>' . '<div class="field">' . '<label for="attr-value-field" class="field-label first required">' .__( 'Value', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</label>' . '<input id="attr-value-field" name="attr-value-field" class="attr-value-field" type="text" value="' . esc_attr( $IXAP382 ) . '"/>' . '</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="' . esc_attr( $IXAP24 ) . '" name="affiliate_id"/>' . '<input type="hidden" value="edit-attribute" name="action"/>' . ' ' . '<a class="cancel button" href="' . $IXAP373 . '">' . __( 'Cancel', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</a>' . '</div>' . '</div>' . '</form>' . '</div>'; echo $IXAP62; } function edit_submit() { global $wpdb, $affiliates_db, $IXAP1; $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 ) ); } $IXAP25 = $affiliates_db->get_tablename( 'affiliates_attributes' ); $IXAP24 = isset( $_POST['affiliate_id'] ) ? $_POST['affiliate_id'] : null; $IXAP365 = isset( $_POST['attr-key-field'] ) ? $_POST['attr-key-field'] : null; $IXAP368 = isset( $_POST['attr-value-field'] ) ? $_POST['attr-value-field'] : null; if ( $IXAP368 !== null ) { $IXAP368 = Affiliates_Attributes::validate_value( $IXAP365, $IXAP368 ); if ( $IXAP368 !== false ) { if ( is_array( $IXAP368 ) || is_object( $IXAP368 ) ) { $IXAP368 = serialize( $IXAP368 ); } } else { $IXAP368 = null; } } $IXAP378 = false; if ( ( $IXAP365 == Affiliates_Attributes::IXAP86 ) && !empty( $IXAP368 ) ) { $IXAP379 = explode( ",", $IXAP368 ); foreach( $IXAP379 as $IXAP380 ) { $IXAP380 = trim( $IXAP380 ); $IXAP381 = self::get_affiliate_for_coupon( $IXAP380 ); if ( ( $IXAP381 !== null ) && ( $IXAP381 != $IXAP24 ) ) { $IXAP1[] = '<div class="error">' . sprintf( __( 'Coupons may not be assigned to multiple affiliates. The coupon code <strong>%s</strong> has already been assigned to the affiliate with Id %d.', AFFILIATES_PRO_PLUGIN_DOMAIN), $IXAP380, $IXAP381 ) . '</div>'; $IXAP378 = true; } } } if ( $IXAP378 ) { return false; } if ( !empty( $IXAP24 ) && Affiliates_Attributes::validate_key( $IXAP365 ) && ( $IXAP368 !== null ) ) { if ( $IXAP383 = $affiliates_db->get_value( "SELECT attr_value FROM $IXAP25 WHERE affiliate_id = %d AND attr_key = %s", $IXAP24, $IXAP365 ) ) { if ( $affiliates_db->query( "UPDATE $IXAP25 SET attr_value=%s WHERE affiliate_id=%d AND attr_key=%s", $IXAP368 , $IXAP24, $IXAP365 ) ) { do_action( 'affiliates_updated_attribute', $IXAP24, $IXAP365, $IXAP383, $IXAP368 ); } } else { $IXAP1[] = '<div class="error">' . __( 'Invalid key', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</div>'; $IXAP15 = false; } } else { $IXAP1[] = '<div class="error">' . __( 'Invalid data', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</div>'; $IXAP15 = false; } return $IXAP15; } function remove( $IXAP24, $IXAP365 ) { global $affiliates_db; if ( !current_user_can( AFFILIATES_ADMINISTER_AFFILIATES ) ) { wp_die( __( 'Access denied.', AFFILIATES_PRO_PLUGIN_DOMAIN ) ); } affiliates_pro_admin_notices(); $IXAP70 = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $IXAP70 = remove_query_arg( 'action', $IXAP70 ); $IXAP70 = remove_query_arg( 'affiliate_id', $IXAP70 ); $IXAP373 = esc_url( $IXAP70 ) . "&action=edit&affiliate_id=" . urlencode( $IXAP24 ); $IXAP70 = remove_query_arg( 'paged', $IXAP70 ); $IXAP25 = $affiliates_db->get_tablename( 'affiliates_attributes' ); $IXAP368 = $affiliates_db->get_value( "SELECT attr_value FROM $IXAP25 WHERE affiliate_id = %d AND attr_key = %s", $IXAP24, $IXAP365 ); $IXAP24 = isset( $_POST['affiliate_id'] ) ? $_POST['affiliate_id'] : $IXAP24; $IXAP365 = isset( $_POST['attr-key-field'] ) ? $_POST['attr-key-field'] : $IXAP365; $IXAP368 = isset( $_POST['attr-value-field'] ) ? $_POST['attr-value-field'] : $IXAP368; $IXAP382 = @unserialize( $IXAP368 ); if ( $IXAP382 === false ) { $IXAP382 = $IXAP368; } if ( is_array( $IXAP382 ) ) { $IXAP382 = implode( "::", $IXAP382 ); } $IXAP273 = Affiliates_Attributes::get_keys(); $IXAP62 = '<div class="manage-affiliates">' . '<div>' . '<h1>' . __( 'Remove an attribute', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</h1>' . '</div>' . '<form id="remove-attribute" action="' . esc_url( $IXAP70 ) . '" method="post">' . '<div class="affiliate-attribute remove">' . '<div class="field">' . '<label for="attr-key-field" class="field-label first required">' .__( 'Key', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</label>' . '<input readonly="readonly" id="attr-name-field" name="attr-name-field" class="attr-name-field" type="text" value="' . esc_attr( $IXAP273[$IXAP365] ) . '"/>' . '<input type="hidden" name="attr-key-field" value="' . esc_attr( $IXAP365 ) . '"/>' . '</div>' . '<div class="field">' . '<label for="attr-value-field" class="field-label first required">' .__( 'Value', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</label>' . '<input readonly="readonly" id="attr-value-field" name="attr-value-field" class="attr-value-field" type="text" value="' . esc_attr( $IXAP382 ) . '"/>' . '</div>' . '<div class="field">' . wp_nonce_field( plugin_basename( __FILE__ ), AFFILIATES_ADMIN_AFFILIATES_NONCE, true, false ) . '<input class="button button-primary" type="submit" value="' . __( 'Remove', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '"/>' . '<input type="hidden" value="' . esc_attr( $IXAP24 ) . '" name="affiliate_id"/>' . '<input type="hidden" value="remove-attribute" name="action"/>' . ' ' . '<a class="cancel button" href="' . $IXAP373 . '">' . __( 'Cancel', AFFILIATES_PRO_PLUGIN_DOMAIN ) . '</a>' . '</div>' . '</div>' . '</form>' . '</div>'; echo $IXAP62; } function remove_submit() { global $wpdb, $affiliates_db, $IXAP1; $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 ) ); } $IXAP25 = $affiliates_db->get_tablename( 'affiliates_attributes' ); $IXAP24 = isset( $_POST['affiliate_id'] ) ? $_POST['affiliate_id'] : null; $IXAP365 = isset( $_POST['attr-key-field'] ) ? $_POST['attr-key-field'] : null; if ( !( empty( $IXAP24 ) || empty( $IXAP365 ) ) ) { $IXAP368 = $affiliates_db->get_value( "SELECT attr_value FROM $IXAP25 WHERE affiliate_id = %d AND attr_key = %s", $IXAP24, $IXAP365 ); if ( $affiliates_db->query( "DELETE FROM $IXAP25 WHERE affiliate_id=%d AND attr_key=%s", $IXAP24, $IXAP365 ) ) { do_action( 'affiliates_removed_attribute', $IXAP24, $IXAP365, $IXAP368 ); } } else { $IXAP15 = false; } return $IXAP15; } public static function get_affiliate_for_coupon( $IXAP380 ) { global $affiliates_db; $IXAP25 = $affiliates_db->get_tablename( "affiliates_attributes" ); $IXAP384 = $affiliates_db->get_objects( "SELECT * FROM $IXAP25 WHERE attr_key = %s AND attr_value LIKE '%%%s%%'", Affiliates_Attributes::IXAP86, $IXAP380 ); $IXAP24 = null; foreach( $IXAP384 as $IXAP385 ) { $IXAP386 = explode( ",", $IXAP385->attr_value ); foreach( $IXAP386 as $IXAP387 ) { $IXAP387 = trim( $IXAP387 ); if ( $IXAP387 === $IXAP380 ) { $IXAP24 = $IXAP385->affiliate_id; break; } } if ( $IXAP24 !== null ) { break; } } return apply_filters( 'affiliates_coupon_affiliate_id', $IXAP24, $IXAP380 ); } public static function get_coupons_for_affiliate( $IXAP24 ) { global $affiliates_db; $IXAP15 = array(); $IXAP25 = $affiliates_db->get_tablename( 'affiliates_attributes' ); if ( $IXAP379 = $affiliates_db->get_value( "SELECT attr_value FROM $IXAP25 WHERE affiliate_id = %d AND attr_key = %s", intval( $IXAP24 ), Affiliates_Attributes::IXAP86 ) ) { $IXAP15 = explode( ',', $IXAP379 ); } return $IXAP15; } public static function set_coupons_for_affiliate( $IXAP24, $IXAP379 = array() ) { global $affiliates_db; $IXAP24 = intval( $IXAP24 ); $IXAP388 = array(); foreach( $IXAP379 as $IXAP380 ) { $IXAP380 = trim( $IXAP380 ); if ( strlen( $IXAP380 ) > 0 ) { $IXAP381 = self::get_affiliate_for_coupon( $IXAP380 ); if ( ( $IXAP381 === null ) || ( $IXAP381 == $IXAP24 ) ) { $IXAP388[] = $IXAP380; } } } $IXAP379 = $IXAP388; $IXAP389 = self::get_coupons_for_affiliate( $IXAP24 ); if ( $IXAP389 != $IXAP379 ) { $IXAP25 = $affiliates_db->get_tablename( 'affiliates_attributes' ); if ( count( $IXAP379 ) == 0 ) { if ( $affiliates_db->query( "DELETE FROM $IXAP25 WHERE affiliate_id=%d AND attr_key=%s", $IXAP24, $IXAP365 ) ) { do_action( 'affiliates_removed_attribute', $IXAP24, Affiliates_Attributes::IXAP86, implode( ',', $IXAP389 ) ); } } else { if ( $IXAP383 = $affiliates_db->get_value( "SELECT attr_value FROM $IXAP25 WHERE affiliate_id = %d AND attr_key = %s", $IXAP24, Affiliates_Attributes::IXAP86 ) ) { if ( $affiliates_db->query( "UPDATE $IXAP25 SET attr_value=%s WHERE affiliate_id=%d AND attr_key=%s", implode( ',', $IXAP379 ) , $IXAP24, Affiliates_Attributes::IXAP86 ) ) { do_action( 'affiliates_updated_attribute', $IXAP24, Affiliates_Attributes::IXAP86, $IXAP383, implode( ',', $IXAP379 ) ); } } else { if ( $affiliates_db->query( "INSERT INTO $IXAP25 SET affiliate_id=%d, attr_key=%s, attr_value=%s", $IXAP24, Affiliates_Attributes::IXAP86, implode( ',', $IXAP379 ) ) ) { do_action( 'affiliates_added_attribute', $IXAP24, Affiliates_Attributes::IXAP86, implode( ',', $IXAP379 ) ); } } } } } }