PluginProbe
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript / 1.9.7
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript v1.9.7
4.1.16 4.1.15 4.1.14 4.1.13 4.1.12 4.1.11 4.1.10 4.0.30 4.0.29 4.0.28 4.0.27 4.0.26 4.0.24 4.0.25 4.0.23 4.0.22 4.0.21 4.0.19 4.0.18 4.0.17 4.0.16 1.9.3 1.9.4 1.9.5 1.9.6 All 170 releases
searchpro / inc / photon / integration / plugin / revolution-slider.php

revolution-slider.php in BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript 1.9.7, at inc/photon/integration/plugin/revolution-slider.php

71 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH')) exit;
3
4 class Revolution_slider {
5 function __construct() {
6 // add_filter('berqwp_before_script_optimization', [$this, 'load_slider']);
7 }
8
9 function load_slider($buffer) {
10 $script = "
11 <script>
12 document.querySelectorAll('rs-module').forEach(function(item){
13 let id = item.getAttribute('id')
14 if (id) {
15 window.revapi4 = window.revapi4 === undefined || window.revapi4 === null || window.revapi4.length === 0 ? document.getElementById(id) : window.revapi4;
16 window.revapi4 = jQuery(window.revapi4);
17 let args = bwp_get_rev_args();
18 revapi4.revolutionInit(args);
19
20 function bwp_get_rev_args() {
21 // Get the script tag by ID
22 let scriptTag = document.getElementById('rs-initialisation-scripts');
23
24 if (scriptTag) {
25 // Extract the content of the script tag
26 var scriptContent = scriptTag.innerHTML;
27
28 // Use a regular expression to find the argument object
29 var regex = /revapi4\.revolutionInit\((\{[\s\S]*?\})\);/;
30 var match = scriptContent.match(regex);
31
32 if (match && match[1]) {
33 // Extract the JSON string
34 var jsonString = match[1]
35 .replace(/(\w+)\s*:/g, '\"$1\":') // Add double quotes around property names
36 .replace(/'/g, '\"') // Replace single quotes with double quotes
37 .replace(/,\s*}/g, '}') // Remove trailing commas before closing brace
38 .replace(/,\s*]/g, ']'); // Remove trailing commas before closing bracket
39
40 try {
41 // Parse the JSON string to an object
42 var initArgs = JSON.parse(jsonString);
43
44 return initArgs;
45
46 // Now you can use initArgs as needed
47 } catch (e) {
48 console.log('Error parsing JSON:', e);
49 }
50 } else {
51 console.log('Initialization arguments not found.');
52 }
53 } else {
54 console.log('Script tag with ID \"rs-initialisation-scripts\" not found.');
55 }
56 }
57 }
58
59 })
60 </script>
61 ";
62
63 if (str_contains($buffer, '<rs-module')) {
64 $buffer = str_replace('</body>', $script . '</body>', $buffer);
65 }
66
67 return $buffer;
68 }
69 }
70
71 new Revolution_slider();