PluginProbe ʕ •ᴥ•ʔ
LiteSpeed Cache / 7.8.1
LiteSpeed Cache v7.8.1
trunk 1.0.15 1.9.1.1 2.9.9.2 3.6.4 4.6 5.7.0.1 6.5.4 7.0.0.1 7.0.1 7.1 7.2 7.3 7.3.0.1 7.4 7.5 7.5.0.1 7.6 7.6.1 7.6.2 7.7 7.8 7.8.0.1 7.8.1
litespeed-cache / src / str.cls.php
litespeed-cache / src Last commit date
cdn 2 months ago data_structure 2 months ago activation.cls.php 2 months ago admin-display.cls.php 2 months ago admin-settings.cls.php 2 months ago admin.cls.php 2 months ago api.cls.php 2 months ago avatar.cls.php 2 months ago base.cls.php 2 months ago cdn.cls.php 2 months ago cloud-auth-callback.trait.php 2 months ago cloud-auth-ip.trait.php 2 months ago cloud-auth.trait.php 2 months ago cloud-misc.trait.php 2 months ago cloud-node.trait.php 2 months ago cloud-request.trait.php 2 months ago cloud.cls.php 2 months ago conf.cls.php 2 months ago control.cls.php 2 months ago core.cls.php 2 months ago crawler-map.cls.php 2 months ago crawler.cls.php 2 months ago css.cls.php 2 months ago data.cls.php 2 months ago data.upgrade.func.php 2 months ago db-optm.cls.php 2 months ago debug2.cls.php 2 months ago doc.cls.php 2 months ago error.cls.php 2 months ago esi.cls.php 2 months ago file.cls.php 2 months ago guest.cls.php 2 months ago gui.cls.php 2 months ago health.cls.php 2 months ago htaccess.cls.php 2 months ago img-optm-manage.trait.php 2 months ago img-optm-pull.trait.php 2 months ago img-optm-send.trait.php 2 months ago img-optm.cls.php 2 months ago import.cls.php 2 months ago import.preset.cls.php 2 months ago lang.cls.php 2 months ago localization.cls.php 2 months ago media.cls.php 2 months ago metabox.cls.php 2 months ago object-cache-wp.cls.php 2 months ago object-cache.cls.php 2 months ago object.lib.php 2 months ago optimize.cls.php 2 months ago optimizer.cls.php 2 months ago placeholder.cls.php 2 months ago purge.cls.php 2 months ago report.cls.php 2 months ago rest.cls.php 2 months ago root.cls.php 2 months ago router.cls.php 2 months ago str.cls.php 2 months ago tag.cls.php 2 months ago task.cls.php 2 months ago tool.cls.php 2 months ago ucss.cls.php 2 months ago utility.cls.php 2 months ago vary.cls.php 2 months ago vpi.cls.php 2 months ago
str.cls.php
143 lines
1 <?php
2 /**
3 * LiteSpeed String Operator Library Class
4 *
5 * @since 1.3
6 * @package LiteSpeed
7 */
8
9 namespace LiteSpeed;
10
11 defined( 'WPINC' ) || exit();
12
13 /**
14 * Class Str
15 *
16 * Provides string manipulation utilities for LiteSpeed Cache.
17 *
18 * @since 1.3
19 */
20 class Str {
21
22 /**
23 * Translate QC HTML links from html.
24 *
25 * Converts `<a href="{#xxx#}">xxxx</a>` to `<a href="xxx">xxxx</a>`.
26 *
27 * @since 7.0
28 * @access public
29 * @param string $html The HTML string to process.
30 * @return string The processed HTML string.
31 */
32 public static function translate_qc_apis( $html ) {
33 preg_match_all( '/<a href="{#(\w+)#}"/U', $html, $matches );
34 if ( ! $matches ) {
35 return $html;
36 }
37
38 foreach ( $matches[0] as $k => $html_to_be_replaced ) {
39 $link = '<a href="' . Utility::build_url( Router::ACTION_CLOUD, Cloud::TYPE_API, false, null, [ 'action2' => $matches[1][ $k ] ] ) . '"';
40 $html = str_replace( $html_to_be_replaced, $link, $html );
41 }
42 return $html;
43 }
44
45 /**
46 * Return safe HTML
47 *
48 * Sanitizes HTML to allow only specific tags and attributes.
49 *
50 * @since 7.0
51 * @access public
52 * @param string $html The HTML string to sanitize.
53 * @return string The sanitized HTML string.
54 */
55 public static function safe_html( $html ) {
56 $common_attrs = [
57 'style' => [],
58 'class' => [],
59 'target' => [],
60 'src' => [],
61 'color' => [],
62 'href' => [],
63 ];
64 $tags = [ 'hr', 'h3', 'h4', 'h5', 'ul', 'li', 'br', 'strong', 'p', 'span', 'img', 'a', 'div', 'font' ];
65 $allowed_tags = [];
66 foreach ( $tags as $tag ) {
67 $allowed_tags[ $tag ] = $common_attrs;
68 }
69
70 return wp_kses( $html, $allowed_tags );
71 }
72
73 /**
74 * Generate random string
75 *
76 * Creates a random string of specified length and character type.
77 *
78 * @since 1.3
79 * @access public
80 * @param int $len Length of string.
81 * @param int $type Character type: 1-Number, 2-LowerChar, 4-UpperChar, 7-All.
82 * @return string Randomly generated string.
83 */
84 public static function rrand( $len, $type = 7 ) {
85 switch ( $type ) {
86 case 0:
87 $charlist = '012';
88 break;
89
90 case 1:
91 $charlist = '0123456789';
92 break;
93
94 case 2:
95 $charlist = 'abcdefghijklmnopqrstuvwxyz';
96 break;
97
98 case 3:
99 $charlist = '0123456789abcdefghijklmnopqrstuvwxyz';
100 break;
101
102 case 4:
103 $charlist = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
104 break;
105
106 case 5:
107 $charlist = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
108 break;
109
110 case 6:
111 $charlist = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
112 break;
113
114 case 7:
115 $charlist = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
116 break;
117 }
118
119 $str = '';
120
121 $max = strlen( $charlist ) - 1;
122 for ( $i = 0; $i < $len; $i++ ) {
123 $str .= $charlist[ random_int( 0, $max ) ];
124 }
125
126 return $str;
127 }
128
129 /**
130 * Trim double quotes from a string
131 *
132 * Removes double quotes from a string for use as a preformatted src in HTML.
133 *
134 * @since 6.5.3
135 * @access public
136 * @param string $text The string to process.
137 * @return string The string with double quotes removed.
138 */
139 public static function trim_quotes( $text ) {
140 return str_replace( '"', '', $text );
141 }
142 }
143