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 / class-scriptSeqManipulate.php

class-scriptSeqManipulate.php in BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript 1.9.7, at inc/class-scriptSeqManipulate.php

101 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class scriptSeqManipulate {
4 public $buffer = null;
5
6 function setBuffer($buffer) {
7 $this->buffer = $buffer;
8 }
9
10 function appendAfter($scriptMatch, $match) {
11 $mainScript = $this->getScript($scriptMatch);
12 $html = str_get_html($this->buffer);
13 $scriptTags = $html->find('script');
14 $matchFound = false;
15
16 foreach ($scriptTags as $script) {
17 if (strpos($script->outertext, $match) !== false) {
18 $script->outertext = $script->outertext . $mainScript;
19 $matchFound = true;
20 break;
21 }
22 }
23
24
25 $this->buffer = $html->save();
26 $html->clear();
27 unset($html);
28
29 // if ($matchFound) {
30 // $this->removeScript($scriptMatch);
31 // }
32 }
33
34 function appendBefore($scriptMatch, $match) {
35 $mainScript = $this->getScript($scriptMatch);
36 $html = str_get_html($this->buffer);
37 $scriptTags = $html->find('script');
38 $matchFound = false;
39
40 foreach ($scriptTags as $script) {
41 if (strpos($script->outertext, $match) !== false) {
42 $script->outertext = $mainScript . $script->outertext;
43 $matchFound = true;
44 break;
45 }
46 }
47
48
49 $this->buffer = $html->save();
50 $html->clear();
51 unset($html);
52
53 // if ($matchFound) {
54 // $this->removeScript($scriptMatch);
55 // }
56 }
57
58 function getScript($scriptMatch) {
59 $html = str_get_html($this->buffer);
60 $scriptTags = $html->find('script');
61 $found_tag = null;
62
63 foreach ($scriptTags as $script) {
64 if (strpos($script->outertext, $scriptMatch) !== false) {
65 $found_tag = $script->outertext;
66 $script->outertext = '';
67 break;
68 }
69 }
70
71 $this->buffer = $html->save();
72 $html->clear();
73 unset($html);
74
75 return $found_tag;
76 }
77
78 function removeScript($match) {
79 $html = str_get_html($this->buffer);
80 $scriptTags = $html->find('script');
81
82 foreach ($scriptTags as $script) {
83 if (strpos($script->outertext, $match) !== false) {
84 $script->outertext = '';
85 break;
86 }
87 }
88
89 $this->buffer = $html->save();
90 $html->clear();
91 unset($html);
92 }
93
94 function getBuffer() {
95 return $this->buffer;
96 }
97
98 function clean() {
99 $this->buffer = null;
100 }
101 }