admin.1778685035.js
3 weeks ago
admin.ajaxWatcher.1778685035.js
3 weeks ago
chart.umd.1778685035.js
3 weeks ago
jquery.qrcode.min.1778685035.js
3 weeks ago
vue.esm-browser.prod.1778685035.js
3 weeks ago
wfdashboard.1778685035.js
3 weeks ago
wfdropdown.1778685035.js
3 weeks ago
wfglobal.1778685035.js
3 weeks ago
wfi18n.1778685035.js
3 weeks ago
wfonboarding.1778685035.js
3 weeks ago
wfpopover.1778685035.js
3 weeks ago
wordfence.1778685035.js
3 weeks ago
wfi18n.1778685035.js
231 lines
| 1 | (function () { |
| 2 | |
| 3 | window.wfi18n = { |
| 4 | __: function(text) { |
| 5 | if (window.WordfenceI18nStrings && text in window.WordfenceI18nStrings) { |
| 6 | return window.WordfenceI18nStrings[text]; |
| 7 | } |
| 8 | return text; |
| 9 | }, |
| 10 | _n: function(singular, plural, count) { |
| 11 | if (count === 1) { |
| 12 | return window.wfi18n.__(singular); |
| 13 | } |
| 14 | return window.wfi18n.__(plural); |
| 15 | } |
| 16 | }; |
| 17 | |
| 18 | if (typeof wp === 'object' && wp.i18n) { |
| 19 | window.wfi18n.sprintf = wp.i18n.sprintf; |
| 20 | return; |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * Code has been adapted from WordPress' i18n.js functions and is being used as a polyfill for WordPress |
| 25 | * versions before 5.0. |
| 26 | */ |
| 27 | var re = { |
| 28 | not_string: /[^s]/, |
| 29 | not_bool: /[^t]/, |
| 30 | not_type: /[^T]/, |
| 31 | not_primitive: /[^v]/, |
| 32 | number: /[diefg]/, |
| 33 | numeric_arg: /[bcdiefguxX]/, |
| 34 | json: /[j]/, |
| 35 | not_json: /[^j]/, |
| 36 | text: /^[^\x25]+/, |
| 37 | modulo: /^\x25{2}/, |
| 38 | placeholder: /^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/, |
| 39 | key: /^([a-z_][a-z_\d]*)/i, |
| 40 | key_access: /^\.([a-z_][a-z_\d]*)/i, |
| 41 | index_access: /^\[(\d+)\]/, |
| 42 | sign: /^[+-]/ |
| 43 | }; |
| 44 | |
| 45 | function sprintf(key) { |
| 46 | // `arguments` is not an array, but should be fine for this call |
| 47 | return sprintf_format(sprintf_parse(key), arguments) |
| 48 | } |
| 49 | |
| 50 | function vsprintf(fmt, argv) { |
| 51 | return sprintf.apply(null, [fmt].concat(argv || [])) |
| 52 | } |
| 53 | |
| 54 | function sprintf_format(parse_tree, argv) { |
| 55 | var cursor = 1, tree_length = parse_tree.length, arg, output = '', i, k, ph, pad, pad_character, pad_length, is_positive, sign |
| 56 | for (i = 0; i < tree_length; i++) { |
| 57 | if (typeof parse_tree[i] === 'string') { |
| 58 | output += parse_tree[i] |
| 59 | } |
| 60 | else if (typeof parse_tree[i] === 'object') { |
| 61 | ph = parse_tree[i] // convenience purposes only |
| 62 | if (ph.keys) { // keyword argument |
| 63 | arg = argv[cursor] |
| 64 | for (k = 0; k < ph.keys.length; k++) { |
| 65 | if (arg == undefined) { |
| 66 | throw new Error(sprintf('[sprintf] Cannot access property "%s" of undefined value "%s"', ph.keys[k], ph.keys[k-1])) |
| 67 | } |
| 68 | arg = arg[ph.keys[k]] |
| 69 | } |
| 70 | } |
| 71 | else if (ph.param_no) { // positional argument (explicit) |
| 72 | arg = argv[ph.param_no] |
| 73 | } |
| 74 | else { // positional argument (implicit) |
| 75 | arg = argv[cursor++] |
| 76 | } |
| 77 | |
| 78 | if (re.not_type.test(ph.type) && re.not_primitive.test(ph.type) && arg instanceof Function) { |
| 79 | arg = arg() |
| 80 | } |
| 81 | |
| 82 | if (re.numeric_arg.test(ph.type) && (typeof arg !== 'number' && isNaN(arg))) { |
| 83 | throw new TypeError(sprintf('[sprintf] expecting number but found %T', arg)) |
| 84 | } |
| 85 | |
| 86 | if (re.number.test(ph.type)) { |
| 87 | is_positive = arg >= 0 |
| 88 | } |
| 89 | |
| 90 | switch (ph.type) { |
| 91 | case 'b': |
| 92 | arg = parseInt(arg, 10).toString(2) |
| 93 | break |
| 94 | case 'c': |
| 95 | arg = String.fromCharCode(parseInt(arg, 10)) |
| 96 | break |
| 97 | case 'd': |
| 98 | case 'i': |
| 99 | arg = parseInt(arg, 10) |
| 100 | break |
| 101 | case 'j': |
| 102 | arg = JSON.stringify(arg, null, ph.width ? parseInt(ph.width) : 0) |
| 103 | break |
| 104 | case 'e': |
| 105 | arg = ph.precision ? parseFloat(arg).toExponential(ph.precision) : parseFloat(arg).toExponential() |
| 106 | break |
| 107 | case 'f': |
| 108 | arg = ph.precision ? parseFloat(arg).toFixed(ph.precision) : parseFloat(arg) |
| 109 | break |
| 110 | case 'g': |
| 111 | arg = ph.precision ? String(Number(arg.toPrecision(ph.precision))) : parseFloat(arg) |
| 112 | break |
| 113 | case 'o': |
| 114 | arg = (parseInt(arg, 10) >>> 0).toString(8) |
| 115 | break |
| 116 | case 's': |
| 117 | arg = String(arg) |
| 118 | arg = (ph.precision ? arg.substring(0, ph.precision) : arg) |
| 119 | break |
| 120 | case 't': |
| 121 | arg = String(!!arg) |
| 122 | arg = (ph.precision ? arg.substring(0, ph.precision) : arg) |
| 123 | break |
| 124 | case 'T': |
| 125 | arg = Object.prototype.toString.call(arg).slice(8, -1).toLowerCase() |
| 126 | arg = (ph.precision ? arg.substring(0, ph.precision) : arg) |
| 127 | break |
| 128 | case 'u': |
| 129 | arg = parseInt(arg, 10) >>> 0 |
| 130 | break |
| 131 | case 'v': |
| 132 | arg = arg.valueOf() |
| 133 | arg = (ph.precision ? arg.substring(0, ph.precision) : arg) |
| 134 | break |
| 135 | case 'x': |
| 136 | arg = (parseInt(arg, 10) >>> 0).toString(16) |
| 137 | break |
| 138 | case 'X': |
| 139 | arg = (parseInt(arg, 10) >>> 0).toString(16).toUpperCase() |
| 140 | break |
| 141 | } |
| 142 | if (re.json.test(ph.type)) { |
| 143 | output += arg |
| 144 | } |
| 145 | else { |
| 146 | if (re.number.test(ph.type) && (!is_positive || ph.sign)) { |
| 147 | sign = is_positive ? '+' : '-' |
| 148 | arg = arg.toString().replace(re.sign, '') |
| 149 | } |
| 150 | else { |
| 151 | sign = '' |
| 152 | } |
| 153 | pad_character = ph.pad_char ? ph.pad_char === '0' ? '0' : ph.pad_char.charAt(1) : ' ' |
| 154 | pad_length = ph.width - (sign + arg).length |
| 155 | pad = ph.width ? (pad_length > 0 ? pad_character.repeat(pad_length) : '') : '' |
| 156 | output += ph.align ? sign + arg + pad : (pad_character === '0' ? sign + pad + arg : pad + sign + arg) |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | return output |
| 161 | } |
| 162 | |
| 163 | var sprintf_cache = Object.create(null) |
| 164 | |
| 165 | function sprintf_parse(fmt) { |
| 166 | if (sprintf_cache[fmt]) { |
| 167 | return sprintf_cache[fmt] |
| 168 | } |
| 169 | |
| 170 | var _fmt = fmt, match, parse_tree = [], arg_names = 0 |
| 171 | while (_fmt) { |
| 172 | if ((match = re.text.exec(_fmt)) !== null) { |
| 173 | parse_tree.push(match[0]) |
| 174 | } |
| 175 | else if ((match = re.modulo.exec(_fmt)) !== null) { |
| 176 | parse_tree.push('%') |
| 177 | } |
| 178 | else if ((match = re.placeholder.exec(_fmt)) !== null) { |
| 179 | if (match[2]) { |
| 180 | arg_names |= 1 |
| 181 | var field_list = [], replacement_field = match[2], field_match = [] |
| 182 | if ((field_match = re.key.exec(replacement_field)) !== null) { |
| 183 | field_list.push(field_match[1]) |
| 184 | while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { |
| 185 | if ((field_match = re.key_access.exec(replacement_field)) !== null) { |
| 186 | field_list.push(field_match[1]) |
| 187 | } |
| 188 | else if ((field_match = re.index_access.exec(replacement_field)) !== null) { |
| 189 | field_list.push(field_match[1]) |
| 190 | } |
| 191 | else { |
| 192 | throw new SyntaxError('[sprintf] failed to parse named argument key') |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | else { |
| 197 | throw new SyntaxError('[sprintf] failed to parse named argument key') |
| 198 | } |
| 199 | match[2] = field_list |
| 200 | } |
| 201 | else { |
| 202 | arg_names |= 2 |
| 203 | } |
| 204 | if (arg_names === 3) { |
| 205 | throw new Error('[sprintf] mixing positional and named placeholders is not (yet) supported') |
| 206 | } |
| 207 | |
| 208 | parse_tree.push( |
| 209 | { |
| 210 | placeholder: match[0], |
| 211 | param_no: match[1], |
| 212 | keys: match[2], |
| 213 | sign: match[3], |
| 214 | pad_char: match[4], |
| 215 | align: match[5], |
| 216 | width: match[6], |
| 217 | precision: match[7], |
| 218 | type: match[8] |
| 219 | } |
| 220 | ) |
| 221 | } |
| 222 | else { |
| 223 | throw new SyntaxError('[sprintf] unexpected placeholder') |
| 224 | } |
| 225 | _fmt = _fmt.substring(match[0].length) |
| 226 | } |
| 227 | return sprintf_cache[fmt] = parse_tree |
| 228 | } |
| 229 | |
| 230 | window.wfi18n.sprintf = sprintf; |
| 231 | })(); |