<commit_before><?php
/**
 * WooCommerce Svea Payments Gateway
 *
 * @package WooCommerce Svea Payments Gateway
 */

/**
 * Svea Payments Gateway Plugin for WooCommerce 3.x, 4.x
 * Plugin developed for Svea
 * Last update: 30/11/2020
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * [GNU LGPL v. 2.1 @gnu.org] (https://www.gnu.org/licenses/lgpl-2.1.html)
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

/**
 * Class WC_Utils_Maksuturva.
 *
 * Static class for filtering characters and prices.
 *
 * @since 2.0.0
 */
class WC_Utils_Maksuturva {

	/**
	 * Filter a string to only have alphanumeric characters.
	 *
	 * @param string $string The string to filter.
	 *
	 * @since 2.1.3
	 *
	 * @return string
	 */
	public static function filter_alphanumeric( $string ) {
		return preg_replace( "/[^a-zA-Z0-9]+/", "", $string );
	}

	/**
	 * Filters a price.
	 *
	 * Applies str_replace and sprintf on the given price.
	 *
	 * @param string|float|int $price The price.
	 *
	 * @since 2.0.0
	 *
	 * @return string
	 */
	public static function filter_price( $price ) {
		return str_replace( '.', ',', sprintf( '%.2f', $price ) );
	}

	/**
	 * Helper function to filter out problematic characters.
	 *
	 * So far only quotation marks have been needed to filter out.
	 *
	 * @param string $string The string to filter.
	 *
	 * @since   2.0.0
	 *
	 * @return string
	 */
	public static function filter_characters( $string ) {
		$new_string = str_replace( '"', '', $string );
		if ( ! is_null( $new_string ) && mb_strlen( $new_string ) > 0 ) {
			return $new_string;
		}

		return ' ';
	}

	/**
	 * Filter a description string.
	 *
	 * Replace information with dash
	 *
	 * @param string $description The description string.
	 *
	 * @since 2.0.0
	 *
	 * @return string
	 */
	public static function filter_description( $description ) {
		/* 2.1.5 item description is not necessary for payment backend, replace with dash if not empty */
		if (trim($description)!='') {
			$description="-";
		}
		//return self::filter_characters( html_entity_decode( strip_tags( $description ) ) );
	}

	/***
	 * Generate S2S User-Agent
	 */
	public static function get_user_agent()
	{
		$user_agent = "Svea Payments for WC/" . WC_Maksuturva::VERSION;

		try {<commit_msg>Estonian special delivery fixes and truncate pmt row description fields.<commit_after><?php
/**
 * WooCommerce Svea Payments Gateway
 *
 * @package WooCommerce Svea Payments Gateway
 */

/**
 * Svea Payments Gateway Plugin for WooCommerce 3.x, 4.x
 * Plugin developed for Svea
 * Last update: 30/11/2020
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * [GNU LGPL v. 2.1 @gnu.org] (https://www.gnu.org/licenses/lgpl-2.1.html)
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

/**
 * Class WC_Utils_Maksuturva.
 *
 * Static class for filtering characters and prices.
 *
 * @since 2.0.0
 */
class WC_Utils_Maksuturva {

	/**
	 * Filter a string to only have alphanumeric characters.
	 *
	 * @param string $string The string to filter.
	 *
	 * @since 2.1.3
	 *
	 * @return string
	 */
	public static function filter_alphanumeric( $string ) {
		return preg_replace( "/[^a-zA-Z0-9]+/", "", $string );
	}

	/**
	 * Filters a price.
	 *
	 * Applies str_replace and sprintf on the given price.
	 *
	 * @param string|float|int $price The price.
	 *
	 * @since 2.0.0
	 *
	 * @return string
	 */
	public static function filter_price( $price ) {
		return str_replace( '.', ',', sprintf( '%.2f', $price ) );
	}

	/**
	 * Helper function to filter out problematic characters.
	 *
	 * So far only quotation marks have been needed to filter out.
	 *
	 * @param string $string The string to filter.
	 *
	 * @since   2.0.0
	 *
	 * @return string
	 */
	public static function filter_characters( $string ) {
		$new_string = str_replace( '"', '', $string );
		if ( ! is_null( $new_string ) && mb_strlen( $new_string ) > 0 ) {
			return $new_string;
		}

		return ' ';
	}

	/**
	 * Filter a description string.
	 *
	 * Replace information with dash
	 *
	 * @param string $description The description string.
	 *
	 * @since 2.0.0
	 *
	 * @return string
	 */
	public static function filter_description( $description ) {
		/* 2.1.5 item description is not necessary for payment backend, replace with dash if not empty */
		if (trim($description)!='') {
			$description="-";
		}
		return $description;
		//return self::filter_characters( html_entity_decode( strip_tags( $description ) ) );
	}

	/***
	 * Generate S2S User-Agent
	 */
	public static function get_user_agent()
	{
		$user_agent = "Svea Payments for WC/" . WC_Maksuturva::VERSION;

		try {
{'fraction_non_alphanumeric': 0.12086925287356322, 'fraction_numerical': 0.014008620689655173, 'mean_word_length': 3.14668652271035, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6525201', 'n_tokens_mistral': 1910, 'n_tokens_neox': 1731, 'n_words': 605}