]*(>|$) # a string that starts with a <, up until the > or the end of the string | # or > # just a > )%x', '', $string); } /** * Returns captcha field markup. * * @return string captcha field markup */ public static function captcha_get( $value ) { $style = 'display:none;'; $field = ''; $field = apply_filters( 'affiliates_captcha_get', $field, $value ); return $field; } /** * Validates a captcha field. * * @param string $field_value field content * @return true if the field validates */ public static function captcha_validates( $field_value = null ) { $result = false; if ( empty( $field_value ) ) { $result = true; } $result = apply_filters( 'affiliates_captcha_validate', $result, $field_value ); return $result; } /** * Retrieves the first post that contains $title. * @param string $title what to search in titles for * @param string $output Optional, default is Object. Either OBJECT, ARRAY_A, or ARRAY_N. * @param string $post_type Optional, default is null meaning any post type. */ public static function get_post_by_title( $title, $output = OBJECT, $post_type = null ) { global $wpdb; $post = null; if ( $post_type == null ) { $query = $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_title LIKE '%%%s%%'", $title ); } else { $query = $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_title LIKE '%%%s%%' AND post_type= %s", $title, $post_type ); } $result = $wpdb->get_row( $query ); if ( !empty( $result ) ) { $post_id = $result->ID; $post = get_post( $post_id, $output ); } return $post; } /** * Verifies and returns formatted amount. * @param string $amount * @return string amount, false upon error or wrong format */ public static function verify_referral_amount( $amount ) { $result = false; if ( is_numeric( $amount ) ) { $amount = sprintf( '%.' . ( affiliates_get_referral_amount_decimals() + 1 ) . 'F', $amount ); if ( preg_match( "/([0-9,]+)?(\.[0-9]+)?/", $amount, $matches ) ) { if ( isset( $matches[1] ) ) { $n = str_replace(",", "", $matches[1] ); } else { $n = "0"; } if ( isset( $matches[2] ) ) { // exceeding decimals are TRUNCATED $d = substr( $matches[2], 1, affiliates_get_referral_amount_decimals() ); } else { $d = "0"; } if ( isset( $matches[1] ) || isset( $matches[2] ) ) { $result = $n . "." . $d; } } } return $result; } /** * Verify and return currency id. * @param string $currency_id * @return string currency id or false on error */ public static function verify_currency_id( $currency_id ) { if ( !empty( $currency_id ) ) { return substr( trim( strtoupper( $currency_id ) ), 0, AFFILIATES_REFERRAL_CURRENCY_ID_LENGTH ); } else { return false; } } /** * Verifies states and transition. * * @param string $old_status * @param string $new_status * @return string|boolean new status or false on failure to verify */ public static function verify_referral_status_transition( $old_status, $new_status ) { $result = false; switch ( $old_status ) { case AFFILIATES_REFERRAL_STATUS_ACCEPTED : case AFFILIATES_REFERRAL_STATUS_CLOSED : case AFFILIATES_REFERRAL_STATUS_PENDING : case AFFILIATES_REFERRAL_STATUS_REJECTED : switch ( $new_status ) { case AFFILIATES_REFERRAL_STATUS_ACCEPTED : case AFFILIATES_REFERRAL_STATUS_CLOSED : case AFFILIATES_REFERRAL_STATUS_PENDING : case AFFILIATES_REFERRAL_STATUS_REJECTED : $result = $new_status; break; } break; } return $result; } /** * Verifies affiliate states. * * @param string $status * @return string|boolean status or false on failure to verify */ public static function verify_affiliate_status( $status ) { $result = false; switch ( $status ) { case AFFILIATES_AFFILIATE_STATUS_ACTIVE : case AFFILIATES_AFFILIATE_STATUS_PENDING : case AFFILIATES_AFFILIATE_STATUS_DELETED : $result = $status; break; } return $result; } }// class Affiliates_Utility