' . '
' . sprintf( __( 'Your site is not using permalinks. You will only be able to use affiliate links but not affiliate permalinks, unless you change your permalink settings.', AFFILIATES_PLUGIN_DOMAIN ), get_admin_url( null, 'options-permalink.php') ) . '
'; } // // handle affiliates form submission // $affiliates_table = _affiliates_get_tablename( 'affiliates' ); if ( wp_verify_nonce( $_POST[AFFILIATES_ADMIN_AFFILIATES_NONCE], plugin_basename( __FILE__ ) ) ) { // mark deleted affiliates as deleted $i = 0; $affiliatecount = intval( $_POST['affiliatecount'] ); while ( ( $_POST['delete-affiliate-id-' . $i] != NULL ) || ( $i <= $affiliatecount ) ) { $affiliate_id = $_POST['delete-affiliate-id-' . $i]; $affiliate_exists = FALSE; // do not mark the pseudo-affiliate as deleted: type != ... $check = $wpdb->prepare( "SELECT affiliate_id FROM $affiliates_table WHERE affiliate_id = %d AND (type IS NULL OR type != '" . AFFILIATES_DIRECT_TYPE . "')", intval( $affiliate_id ) ); if ( $wpdb->query( $check ) ) { $affiliate_exists = TRUE; } if ( $affiliate_exists ) { $wpdb->query( $query = $wpdb->prepare( "UPDATE $affiliates_table SET status = 'deleted' WHERE affiliate_id = %d", intval( $affiliate_id ) ) ); } $i++; } // add or modify affiliate entries $i = 0; $affiliatecount = intval( $_POST['affiliatecount'] ); while ( ( $_POST['name-field-' . $i] != NULL ) || ( $i <= $affiliatecount ) ) { $affiliate_id = $_POST['affiliate-id-' . $i]; $affiliate_exists = false; $is_direct = false; if ( $the_affiliate = $wpdb->get_row( $wpdb->prepare( "SELECT affiliate_id FROM $affiliates_table WHERE affiliate_id = %d", intval( $affiliate_id ) ) ) ) { $affiliate_exists = true; $is_direct = $the_affiliate->type == AFFILIATES_DIRECT_TYPE; } $name = $_POST['name-field-' . $i]; // don't change the name of the pseudo-affiliate if ( $is_direct ) { $name = AFFILIATES_DIRECT_NAME; } if ( !empty( $name ) ) { // Note the trickery (*) that has to be used because wpdb::prepare() is not // able to handle null values. // @see http://core.trac.wordpress.org/ticket/11622 // @see http://core.trac.wordpress.org/ticket/12819 $data = array( 'name' => $name ); $formats = array( '%s' ); $email = trim( $_POST['email-field-' . $i] ); if ( is_email( $email ) ) { $data['email'] = $email; $formats[] = '%s'; } else { $data['email'] = null; // (*) $formats[] = 'NULL'; // (*) } $from_date = $_POST['from-date-field-' . $i]; if ( empty( $from_date ) ) { $from_date = date( 'Y-m-d', time() ); } else { $from_date = date( 'Y-m-d', strtotime( $from_date ) ); } $data['from_date'] = $from_date; $formats[] = '%s'; $thru_date = $_POST['thru-date-field-' . $i]; if ( !empty( $thru_date ) && strtotime( $thru_date ) < strtotime( $from_date ) ) { // thru_date is before from_date => set to null $thru_date = null; } if ( !empty( $thru_date ) ) { $thru_date = date( 'Y-m-d', strtotime( $thru_date ) ); $data['thru_date'] = $thru_date; $formats[] = '%s'; } else { $data['thru_date'] = null; // (*) $formats[] = 'NULL'; // (*) } if ( $affiliate_exists ) { $sets = array(); $values = array(); $j = 0; foreach( $data as $key => $value ) { $sets[] = $key . ' = ' . $formats[$j]; if ( $value ) { // (*) $values[] = $value; } $j++; } if ( !empty( $sets ) ) { $sets = implode( ', ', $sets ); $values[] = intval( $affiliate_id ); $query = $wpdb->prepare( "UPDATE $affiliates_table SET $sets WHERE affiliate_id = %d", $values ); $wpdb->query( $query ); } } else { $data_ = array(); $formats_ = array(); foreach( $data as $key => $value ) { // (*) if ( $value ) { $data_[$key] = $value; } } foreach( $formats as $format ) { // (*) if ( $format != "NULL" ) { $formats_[] = $format; } } $wpdb->insert( $affiliates_table, $data_, $formats_ ); } } // if $i++; } // while } // if (nonce) // // print the Affiliates form // echo '' . __( 'There are two types of links your affiliates may use to link to your site:', AFFILIATES_PLUGIN_DOMAIN ) . '
' . '' . __( 'Affiliate link', AFFILIATES_PLUGIN_DOMAIN ) . '
' . '' . __( 'This link uses a parameter in the URL to record vists you receive through your affiliates.', AFFILIATES_PLUGIN_DOMAIN ) . __( 'The affiliate information is removed once a visitor has landed on your site.', AFFILIATES_PLUGIN_DOMAIN ) . __( 'You may also append the ?affiliates=... part to links to your posts.', AFFILIATES_PLUGIN_DOMAIN ) . '
' . '' . __( 'Affiliate permalink', AFFILIATES_PLUGIN_DOMAIN ) . '
' . '' . __( 'This link uses a nicer URL to record vists you receive through your affiliates.', AFFILIATES_PLUGIN_DOMAIN ) . __( 'The affiliate information is removed once a visitor has landed on your site.', AFFILIATES_PLUGIN_DOMAIN ) . '
' . '' . __( 'Once a visitor has landed on your site through an affiliate link, referrals may be recorded and attributed to the affiliate.', AFFILIATES_PLUGIN_DOMAIN ) . '
'; echo ''; affiliates_footer(); } ?>