PluginProbe
Block Animations, Motion & Scroll Effects – Ghost Kit / 3.7.0
Block Animations, Motion & Scroll Effects – Ghost Kit v3.7.0
3.7.2 3.7.1 3.7.0 3.6.1 trunk 1.6.3 2.25.0 3.3.0 3.3.1 3.3.2 3.3.3 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.5.0 3.5.1 3.6.0
ghostkit / gutenberg / utils / encode-decode / index.php

index.php in Block Animations, Motion & Scroll Effects – Ghost Kit 3.7.0, at gutenberg/utils/encode-decode/index.php

76 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Encode/Decode helper functions.
4 *
5 * @package ghostkit
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 /**
13 * Encode string.
14 *
15 * @param string|array $str - string to encode.
16 *
17 * @return string|array
18 */
19 function ghostkit_encode( $str ) {
20 // Array.
21 if ( is_array( $str ) ) {
22 $result = array();
23
24 foreach ( $str as $k => $val ) {
25 $result[ ghostkit_encode( $k ) ] = ghostkit_encode( $val );
26 }
27
28 return $result;
29 }
30
31 // String.
32 if ( is_string( $str ) ) {
33 // Because of these replacements, some attributes can't be exported to XML without being broken. So, we need to replace it manually with something safe.
34 // https://github.com/WordPress/gutenberg/blob/88645e4b268acf5746e914159e3ce790dcb1665a/packages/blocks/src/api/serializer.js#L246-L271 .
35 $str = str_replace( '--', '_u002d__u002d_', $str );
36
37 // phpcs:ignore
38 $str = rawurlencode( $str );
39 }
40
41 return $str;
42 }
43
44 /**
45 * Decode string.
46 *
47 * @param string|array $str - string to decode.
48 *
49 * @return string|array
50 */
51 function ghostkit_decode( $str ) {
52 // Array.
53 if ( is_array( $str ) ) {
54 $result = array();
55
56 foreach ( $str as $k => $val ) {
57 $result[ ghostkit_decode( $k ) ] = ghostkit_decode( $val );
58 }
59
60 return $result;
61 }
62
63 // String.
64 if ( is_string( $str ) ) {
65 // Previously we used urldecode() function, but it doesn't work properly with `+` character.
66 // For example, there styles will be broken: width: calc( 100% + 20px );.
67 $str = rawurldecode( $str );
68
69 // Because of these replacements, some attributes can't be exported to XML without being broken. So, we need to replace it manually with something safe.
70 // https://github.com/WordPress/gutenberg/blob/88645e4b268acf5746e914159e3ce790dcb1665a/packages/blocks/src/api/serializer.js#L246-L271 .
71 $str = str_replace( '_u002d__u002d_', '--', $str );
72 }
73
74 return $str;
75 }
76