]*(>|$) # 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 captcha field markup */ static function captcha_get( $value ) { $style = 'display:none;'; $field = ''; return $field; } /** * Validates a captcha field. * * @param string $field_value field content * @return true if the field validates */ static function captcha_validates( $field_value = null ) { $result = false; if ( empty( $field_value ) ) { $result = true; } 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. */ 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 */ static function verify_referral_amount( $amount ) { $result = false; if ( !empty( $amount ) && preg_match( "/([0-9,]+)?(\.[0-9]+)?/", $amount, $matches ) ) { if ( !empty( $matches[1] ) ) { $n = str_replace(",", "", $matches[1] ); } else { $n = "0"; } if ( !empty( $matches[2] ) ) { // exceeding decimals are TRUNCATED $d = substr( $matches[2], 1, AFFILIATES_REFERRAL_AMOUNT_DECIMALS ); } else { $d = "0"; } $result = $n . "." . $d; } return $result; } /** * Verify and return currency id. * @param string $currency_id * @return string currency id or false on error */ 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 new status or false on failure to verify */ 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; } }// class Affiliates_Utility ?>