', $sizes , '
truncate(-1.49999, 2); // returns -1.49 * truncate(.49999, 3); // returns 0.499 * float $val Float number to be truncate * int f Number of precision * return float */ public function truncate($val, $f="0") { if ( ( $p = strpos($val, '.') ) !== false ) { $val = floatval( substr( $val, 0, $p + 1 + $f ) ); } return $val; } // http://php.net/manual/en/function.round.php /Mojo urk solution public function round_down($value, $precision) { $value = (float) $value; $precision = (int) $precision; if ($precision < 0) { $precision = 0; } $decPointPosition = strpos($value, '.'); if ($decPointPosition === false) { return $value; } return (float) ( substr($value, 0, $decPointPosition + $precision + 1) ); } public function round_up($value, $precision) { $value = (float) $value; $precision = (int) $precision; if ($precision < 0) { $precision = 0; } $decPointPosition = strpos($value, '.'); if ($decPointPosition === false) { return $value; } $floorValue = (float) ( substr($value, 0, $decPointPosition + $precision + 1) ); $followingDecimals = (int) substr($value, $decPointPosition + $precision + 1); if ($followingDecimals) { $ceilValue = $floorValue + pow(10, -$precision); // does this give always right result? } else { $ceilValue = $floorValue; } return $ceilValue; } // gets the current post type in the WordPress Admin public function get_current_post_type() { global $post, $typenow, $current_screen, $pagenow; //we have a post so we can just get the post type from that if ( $post && $post->post_type ) { return $post->post_type; } //check the global $typenow - set in admin.php elseif ( $typenow ) { return $typenow; } //check the global $current_screen object - set in sceen.php elseif ( $current_screen && $current_screen->post_type ) { return $current_screen->post_type; } //check the post_type querystring elseif ( isset( $_REQUEST['post_type'] ) ) { return sanitize_key( $_REQUEST['post_type'] ); } //lastly check if post ID is in query string elseif ( isset( $_REQUEST['post'] ) ) { return get_post_type( $_REQUEST['post'] ); } else if ( $pagenow == 'edit.php' ) { $type = 'post'; } //we do not know the post type! return null; } public function product_force_external( $post_id ) { delete_transient( "wc_product_type_$post_id" ); set_transient( "wc_product_type_$post_id", 'external'); wp_set_object_terms( $post_id, 'external', 'product_type' ); } // Retrieve remote image dimensions - getimagesize alternative (it needs GD & CURL libraries) public function getimagesize( $url ) { $ret = array( 'status' => 'invalid', 'msg' => '', 'size' => array(0, 0), ); //phpinfo(); echo __FILE__ . ":" . __LINE__;die . PHP_EOL; if( !(extension_loaded("curl") && function_exists('curl_init')) ) { $ret = array_replace_recursive( $ret, array( 'msg' => 'CURL library is not installed!', )); return $ret; } if( !(extension_loaded("gd") && function_exists('imagecreatefromstring')) ) { $ret = array_replace_recursive( $ret, array( 'msg' => 'GD library is not installed!', )); return $ret; } $input_params = array( 'followlocation' => true, ); $output_params = array( //'parse_headers' => true, //'resp_is_json' => true, 'resp_add_http_code' => true, ); $output = $this->the_plugin->curl( $url, $input_params, $output_params, true ); //var_dump('', $output , ''); echo __FILE__ . ":" . __LINE__;die . PHP_EOL; if ( $output['status'] === 'invalid' || (int) $output['http_code'] !== 200 ) { $msg = sprintf( __('curl error; http code: %s; details: %s', 'woozone'), $output['http_code'], $output['data'] ); //var_dump('', $msg , ''); echo __FILE__ . ":" . __LINE__; die . PHP_EOL; $ret = array_replace_recursive( $ret, array( 'msg' => $msg, )); return $ret; } //var_dump('', $output , ''); echo __FILE__ . ":" . __LINE__;die . PHP_EOL; $data = $output['data']; // Process image $image = imagecreatefromstring( $data ); $dims = array( imagesx( $image ), imagesy( $image ) ); imagedestroy($image); $ret = array_replace_recursive( $ret, array( 'status' => 'valid', 'size' => $dims, 'msg' => 'successfully retrieved remote image size.', )); return $ret; } /** * Add or update a WordPress option. * The option will _not_ auto-load. * * @param string $name * @param mixed $value */ // Add or update a WordPress option without auto loading it. public function add_or_update( $name, $value ) { $success = add_option( $name, $value, '', 'no' ); if ( ! $success ) { $success = update_option( $name, $value ); } return $success; } //==================================================================================== //== Unicode UTF8 public function utf8_trim( $text ) { $patt_repl = array( // like mb_trim() -- remove all leading and trailing whitespace and control characters. DO NOT ADD m FLAG TO PATTERN, THAT WILL DAMAGE THE STRING '/^[\s\pC]+|[\s\pC]+$/u' => '', // cleans 2 or more new lines (uninterupted by non-white space characters) '/[\s\pC]*?(\R)[\s\pC]*?(\R)[\s\pC]*/u' => "\n\n", // cleans single new lines '/(?!\R)[\h\pC]*\R[\h\pC]*(?!\R)/u' => "\n", // convert 1 or more non-newline white-spaces and control characters to single space '/\n+(*SKIP)(*FAIL)|[\h\pC]+/u' => ' ' ); $text = preg_replace( array_keys($patt_repl), $patt_repl, $text ); $text = htmlspecialchars( $text, ENT_HTML5, 'UTF-8' ); return $text; } public function utf8_trim_v2( $str ) { return preg_replace('/^[\pZ\pC]+([\PZ\PC]*)[\pZ\pC]+$/u', '$1', $str); } } }
', $output , '
', $msg , '