$value) { $workArray[] = $value; } $returnString = ''; # Initialize return string $arraySize = count( $workArray ); # Get size of array for ( $i=0; $i<$arraySize; $i++ ) { // Nested array, process nest item if ( is_array( $workArray[$i] ) ) { $returnString .= self::str_putcsv( $workArray[$i], $delimiter, $enclosure, $terminator ); } else { switch ( gettype( $workArray[$i] ) ) { // Manually set some strings case "NULL": $_spFormat = ''; break; case "boolean": $_spFormat = ($workArray[$i] == true) ? 'true': 'false'; break; // Make sure sprintf has a good datatype to work with case "integer": $_spFormat = '%i'; break; case "double": $_spFormat = '%0.2f'; break; case "string": $_spFormat = '%s'; $workArray[$i] = str_replace("$enclosure", "$enclosure$enclosure", $workArray[$i]); break; // Unknown or invalid items for a csv - note: the datatype of array is already handled above, assuming the data is nested case "object": case "resource": default: $_spFormat = ''; break; } $returnString .= sprintf('%2$s'.$_spFormat.'%2$s', $workArray[$i], $enclosure); $returnString .= ($i < ($arraySize-1)) ? $delimiter : $terminator; } } // Done the workload, return the output information return $returnString; } public static function get_query_string( $key, $default = FALSE ) { if( ! isset( $_GET[ $key ] ) ) return $default; $value = self::htmlspecialchars( $_GET[ $key ] ); if( is_array( $value ) ) $value = $value[ 0 ]; return $value; } public static function sanitize_text_field( $data ) { if( is_array( $data ) ){ return array_map( array( 'self', 'sanitize_text_field' ), $data ); } return sanitize_text_field( $data ); } public static function get_plugin_version( $plugin ) { $plugins = get_plugins(); if( ! isset( $plugins[ $plugin ] ) ) return false; return $plugins[ $plugin ][ 'Version' ]; } public static function is_func_disabled( $function ) { if( ! function_exists( $function ) ) return true; $disabled = explode( ',', ini_get( 'disable_functions' ) ); return in_array( $function, $disabled ); } public static function maybe_unserialize( $original ) { // Repalcement for https://codex.wordpress.org/Function_Reference/maybe_unserialize if ( is_serialized( $original ) ){ // Ported with php5.2 support from https://magp.ie/2014/08/13/php-unserialize-string-after-non-utf8-characters-stripped-out/ $parsed = preg_replace_callback( '!s:(\d+):"(.*?)";!s', array( 'self', 'parse_utf8_serialized' ), $original ); $parsed = @unserialize( $parsed ); return ( $parsed ) ? $parsed : unserialize( $original ); // Fallback if parse error. } return $original; } /** * Function to get this installation's TLS version * * Since 3.0 * * @return float OR false */ public static function get_tls() { $php_ver = phpversion(); // If we have a php version lower than 5.6, bail. if( version_compare( $php_ver, '5.6.0', '<' ) ) return false; // Get the user's TLS version. // If we have a php version of 7.0 or higher... if( version_compare( $php_ver, '7.0.0', '>=' ) ) { $meta = stream_get_meta_data( fopen( 'https://ninjaforms.com/', 'r' ) ); $tls = $meta[ 'crypto' ][ 'protocol' ]; } // Otherwise (php version between 5.6 and 7.0)... else { $ctx = stream_context_create( array( 'ssl' => array( 'capture_session_meta' => TRUE ) ) ); $html = file_get_contents( 'https://ninjaforms.com/', FALSE, $ctx ); $meta = stream_context_get_options( $ctx ); $tls = $meta[ 'ssl' ][ 'session_meta' ][ 'protocol' ]; unset( $ctx ); } // If we got a TLS version number... if( false !== strpos( $tls, 'TLSv' ) ) { $ver = substr( $tls, strpos( $tls, 'TLSv' ) + 4 ); return floatval( $ver ); } else { return false; } } private static function parse_utf8_serialized( $matches ) { if ( isset( $matches[2] ) ){ return 's:'.strlen($matches[2]).':"'.$matches[2].'";'; } } } // End Class WPN_Helper