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