Version Description
- Autoconvert iframe vimeo + facebook likebox
Download this release
Release Info
Developer | Facens |
Plugin | iubenda Cookie Solution for GDPR |
Version | 1.9.14 |
Comparing to | |
See all releases |
Code changes from version 1.9.7 to 1.9.14
- assets/banner-1544x500..png +0 -0
- assets/banner-1544x500.jpg +0 -0
- assets/banner-772x250.jpg +0 -0
- assets/banner-772x250.png +0 -0
- assets/screenshot-1.png +0 -0
- assets/screenshot-2.png +0 -0
- iubenda-cookie-class/iubenda.class.php +254 -0
- iubenda-cookie-class/simple_html_dom.php +1740 -0
- iubenda-cookie-class/test.php +92 -0
- iubenda-cookie-class/usage.php +26 -0
- iubenda_cookie_solution.php +14 -166
- readme.txt +39 -11
- simple_html_dom.php +3 -3
assets/banner-1544x500..png
ADDED
Binary file
|
assets/banner-1544x500.jpg
ADDED
Binary file
|
assets/banner-772x250.jpg
ADDED
Binary file
|
assets/banner-772x250.png
ADDED
Binary file
|
assets/screenshot-1.png
ADDED
Binary file
|
assets/screenshot-2.png
ADDED
Binary file
|
iubenda-cookie-class/iubenda.class.php
ADDED
@@ -0,0 +1,254 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Page {
|
4 |
+
|
5 |
+
const IUB_REGEX_PATTERN = '/<!--IUB_COOKIE_POLICY_START-->(.*)<!--IUB_COOKIE_POLICY_END-->/sU';
|
6 |
+
|
7 |
+
public $auto_script_tags = array(
|
8 |
+
'platform.twitter.com/widgets.js',
|
9 |
+
'apis.google.com/js/plusone.js',
|
10 |
+
'apis.google.com/js/platform.js',
|
11 |
+
'connect.facebook.net',
|
12 |
+
'www.youtube.com/iframe_api',
|
13 |
+
'pagead2.googlesyndication.com/pagead/show_ads.js',
|
14 |
+
'pagead2.googlesyndication.com/pagead/js/adsbygoogle.js'
|
15 |
+
);
|
16 |
+
|
17 |
+
public $auto_iframe_tags = array(
|
18 |
+
'youtube.com',
|
19 |
+
'platform.twitter.com',
|
20 |
+
'www.facebook.com/plugins/like.php',
|
21 |
+
'www.facebook.com/plugins/likebox.php',
|
22 |
+
'apis.google.com',
|
23 |
+
'www.google.com/maps/embed/',
|
24 |
+
'player.vimeo.com/video'
|
25 |
+
);
|
26 |
+
|
27 |
+
public $iub_comments_detected = array();
|
28 |
+
public $iframe_detected = array();
|
29 |
+
public $iframe_converted = array();
|
30 |
+
public $scripts_detected = array();
|
31 |
+
public $scripts_inline_detected = array();
|
32 |
+
public $scripts_inline_converted = array();
|
33 |
+
public $scripts_converted = array();
|
34 |
+
|
35 |
+
|
36 |
+
/*
|
37 |
+
construct: the whole HTML output of the page
|
38 |
+
*/
|
39 |
+
public function __construct($content_page){
|
40 |
+
$this->original_content_page = $content_page;
|
41 |
+
$this->content_page = $content_page;
|
42 |
+
}
|
43 |
+
|
44 |
+
/*
|
45 |
+
print iubenda banner, parameter: the script code of iubenda to print the banner
|
46 |
+
*/
|
47 |
+
public function print_banner($banner){
|
48 |
+
return $banner.="
|
49 |
+
<script>
|
50 |
+
(function(){
|
51 |
+
|
52 |
+
function extendObj() {
|
53 |
+
for (var i = 1; i < arguments.length; i++)
|
54 |
+
for (var key in arguments[i])
|
55 |
+
if (arguments[i].hasOwnProperty(key))
|
56 |
+
arguments[0][key] = arguments[i][key];
|
57 |
+
return arguments[0];
|
58 |
+
}
|
59 |
+
|
60 |
+
|
61 |
+
var userCallback, extend;
|
62 |
+
|
63 |
+
if(typeof(_iub.csConfiguration.callback) !== 'undefined'){
|
64 |
+
userCallback = _iub.csConfiguration.callback.onConsentGiven || function(){};
|
65 |
+
}else{
|
66 |
+
userCallback = function(){};
|
67 |
+
}
|
68 |
+
|
69 |
+
extend = {
|
70 |
+
callback: {
|
71 |
+
onConsentGiven: function(){
|
72 |
+
userCallback();
|
73 |
+
jQuery('noscript._no_script_iub').each(function(a,b){
|
74 |
+
var el = jQuery(b);
|
75 |
+
el.after(el.html());
|
76 |
+
});
|
77 |
+
}
|
78 |
+
}
|
79 |
+
};
|
80 |
+
|
81 |
+
extendObj(_iub.csConfiguration, extend);
|
82 |
+
})();
|
83 |
+
</script>";
|
84 |
+
}
|
85 |
+
|
86 |
+
/*
|
87 |
+
Static, utility function: Return true if the user has already given consent on the page
|
88 |
+
*/
|
89 |
+
static function consent_given(){
|
90 |
+
foreach($_COOKIE as $key => $value){
|
91 |
+
if(Page::strpos_array($key, array('_iub_cs-s', '_iub_cs'))){
|
92 |
+
return true;
|
93 |
+
}
|
94 |
+
}
|
95 |
+
}
|
96 |
+
/*
|
97 |
+
Static, utility function: strpos for array
|
98 |
+
*/
|
99 |
+
static function strpos_array($haystack, $needle){
|
100 |
+
if(is_array($needle)){
|
101 |
+
foreach($needle as $need){
|
102 |
+
if(strpos($haystack, $need) !== false){
|
103 |
+
return true;
|
104 |
+
}
|
105 |
+
}
|
106 |
+
}else{
|
107 |
+
if(strpos($haystack, $need) !== false) {
|
108 |
+
return true;
|
109 |
+
}
|
110 |
+
}
|
111 |
+
return false;
|
112 |
+
}
|
113 |
+
|
114 |
+
|
115 |
+
/* Convert scripts, iframe and other code inside IUBENDAs comment in text/plain to not generate cookies */
|
116 |
+
public function create_tags($html){
|
117 |
+
|
118 |
+
$elements = $html->find("*");
|
119 |
+
$js = '';
|
120 |
+
|
121 |
+
if(is_array($elements)){
|
122 |
+
$count = count($elements);
|
123 |
+
for($j=0; $j<$count; $j++){
|
124 |
+
$e = $elements[$j];
|
125 |
+
switch($e->tag){
|
126 |
+
case 'script':
|
127 |
+
$class = $e->class;
|
128 |
+
$e->class = $class . ' _iub_cs_activate';
|
129 |
+
$e->type = 'text/plain';
|
130 |
+
$js.= $e->outertext;
|
131 |
+
break;
|
132 |
+
|
133 |
+
case 'iframe':
|
134 |
+
$new_src = "data:text/html;base64,PGh0bWw+PGJvZHk+U3VwcHJlc3NlZDwvYm9keT48L2h0bWw+";
|
135 |
+
$class = $e->class;
|
136 |
+
$e->suppressedsrc = $e->$src;
|
137 |
+
$e->src = $new_src;
|
138 |
+
$e->class = $class . ' _iub_cs_activate';
|
139 |
+
$js.= $e->outertext;
|
140 |
+
break;
|
141 |
+
|
142 |
+
default:
|
143 |
+
$js.= '<noscript class="_no_script_iub">';
|
144 |
+
$js.= $e->outertext;
|
145 |
+
$js.= '</noscript>';
|
146 |
+
break;
|
147 |
+
}
|
148 |
+
}
|
149 |
+
}
|
150 |
+
return $js;
|
151 |
+
}
|
152 |
+
|
153 |
+
/* Parse all IUBENDAs comment and convert the code inside with create_tags method */
|
154 |
+
public function parse_iubenda_comments(){
|
155 |
+
preg_match_all(self::IUB_REGEX_PATTERN, $this->content_page, $scripts);
|
156 |
+
if(is_array($scripts[1])){
|
157 |
+
$count = count($scripts[1]);
|
158 |
+
$js_scripts = array();
|
159 |
+
for($j=0; $j<$count; $j++){
|
160 |
+
$this->iub_comments_detected[] = $scripts[1][$j];
|
161 |
+
$html = str_get_html($scripts[1][$j], $lowercase=true, $forceTagsClosed=true, $stripRN=false);
|
162 |
+
$js_scripts[] = $this->create_tags($html);
|
163 |
+
}
|
164 |
+
|
165 |
+
if(is_array($scripts[1]) && is_array($js_scripts)){
|
166 |
+
if(count($scripts[1]) >= 1 && count($js_scripts) >= 1){
|
167 |
+
$this->content_page = strtr($this->content_page, array_combine($scripts[1], $js_scripts));
|
168 |
+
}
|
169 |
+
}
|
170 |
+
}
|
171 |
+
}
|
172 |
+
|
173 |
+
/* Parse automatically all the scripts in the page and converts it in text/plain
|
174 |
+
if src or the whole output has inside one of the elements in $auto_script_tags array */
|
175 |
+
public function parse_scripts(){
|
176 |
+
|
177 |
+
$html = str_get_html($this->content_page, $lowercase=true, $forceTagsClosed=true, $stripRN=false);
|
178 |
+
if(is_object($html)){
|
179 |
+
$scripts = $html->find("script");
|
180 |
+
if(is_array($scripts)){
|
181 |
+
$count = count($scripts);
|
182 |
+
for($j=0; $j<$count; $j++){
|
183 |
+
$s = $scripts[$j];
|
184 |
+
if($s->innertext){
|
185 |
+
$this->scripts_detected[] = $s->innertext;
|
186 |
+
if (Page::strpos_array($s->innertext, $this->auto_script_tags) !== false) {
|
187 |
+
$class = $s->class;
|
188 |
+
$s->class = $class . ' _iub_cs_activate';
|
189 |
+
$s->type = 'text/plain';
|
190 |
+
$this->scripts_converted[] = $s->innertext;
|
191 |
+
}
|
192 |
+
}else{
|
193 |
+
$src = $s->src;
|
194 |
+
if($src){
|
195 |
+
$this->scripts_inline_detected[] = $src;
|
196 |
+
if (Page::strpos_array($src, $this->auto_script_tags) !== false) {
|
197 |
+
$class = $s->class;
|
198 |
+
$s->class = $class . ' _iub_cs_activate-inline';
|
199 |
+
$s->type = 'text/plain';
|
200 |
+
$this->scripts_inline_converted[] = $src;
|
201 |
+
}
|
202 |
+
}
|
203 |
+
}
|
204 |
+
}
|
205 |
+
}
|
206 |
+
$this->content_page = $html;
|
207 |
+
}
|
208 |
+
}
|
209 |
+
|
210 |
+
/* Parse automatically all the iframe in the page and change the src to suppressedsrc
|
211 |
+
if src has inside one of the elements in $auto_iframe_tags array */
|
212 |
+
public function parse_iframe(){
|
213 |
+
$html = str_get_html($this->content_page, $lowercase=true, $forceTagsClosed=true, $stripRN=false);
|
214 |
+
if(is_object($html)){
|
215 |
+
$iframes = $html->find("iframe");
|
216 |
+
if(is_array($iframes)){
|
217 |
+
$count = count($iframes);
|
218 |
+
for($j=0; $j<$count; $j++){
|
219 |
+
$i = $iframes[$j];
|
220 |
+
$src = $i->src;
|
221 |
+
$this->iframe_detected[] = $src;
|
222 |
+
if (Page::strpos_array($src, $this->auto_iframe_tags) !== false){
|
223 |
+
$new_src = "data:text/html;base64,PGh0bWw+PGJvZHk+U3VwcHJlc3NlZDwvYm9keT48L2h0bWw+";
|
224 |
+
$class = $i->class;
|
225 |
+
$i->suppressedsrc = $src;
|
226 |
+
$i->src = $new_src;
|
227 |
+
$i->class = $class . ' _iub_cs_activate';
|
228 |
+
$this->iframe_converted[] = $src;
|
229 |
+
}
|
230 |
+
}
|
231 |
+
}
|
232 |
+
$this->content_page = $html;
|
233 |
+
}
|
234 |
+
}
|
235 |
+
|
236 |
+
/*
|
237 |
+
Call three methods to parse the page, iubendas comment, scripts + iframe
|
238 |
+
*/
|
239 |
+
public function parse(){
|
240 |
+
$this->parse_iubenda_comments();
|
241 |
+
$this->parse_scripts();
|
242 |
+
$this->parse_iframe();
|
243 |
+
}
|
244 |
+
|
245 |
+
/*
|
246 |
+
Return the final page to output
|
247 |
+
*/
|
248 |
+
public function get_converted_page(){
|
249 |
+
return $this->content_page;
|
250 |
+
}
|
251 |
+
|
252 |
+
}
|
253 |
+
|
254 |
+
?>
|
iubenda-cookie-class/simple_html_dom.php
ADDED
@@ -0,0 +1,1740 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Website: http://sourceforge.net/projects/simplehtmldom/
|
4 |
+
* Additional projects that may be used: http://sourceforge.net/projects/debugobject/
|
5 |
+
* Acknowledge: Jose Solorzano (https://sourceforge.net/projects/php-html/)
|
6 |
+
* Contributions by:
|
7 |
+
* Yousuke Kumakura (Attribute filters)
|
8 |
+
* Vadim Voituk (Negative indexes supports of "find" method)
|
9 |
+
* Antcs (Constructor with automatically load contents either text or file/url)
|
10 |
+
*
|
11 |
+
* all affected sections have comments starting with "PaperG"
|
12 |
+
*
|
13 |
+
* Paperg - Added case insensitive testing of the value of the selector.
|
14 |
+
* Paperg - Added tag_start for the starting index of tags - NOTE: This works but not accurately.
|
15 |
+
* This tag_start gets counted AFTER \r\n have been crushed out, and after the remove_noice calls so it will not reflect the REAL position of the tag in the source,
|
16 |
+
* it will almost always be smaller by some amount.
|
17 |
+
* We use this to determine how far into the file the tag in question is. This "percentage will never be accurate as the $dom->size is the "real" number of bytes the dom was created from.
|
18 |
+
* but for most purposes, it's a really good estimation.
|
19 |
+
* Paperg - Added the forceTagsClosed to the dom constructor. Forcing tags closed is great for malformed html, but it CAN lead to parsing errors.
|
20 |
+
* Allow the user to tell us how much they trust the html.
|
21 |
+
* Paperg add the text and plaintext to the selectors for the find syntax. plaintext implies text in the innertext of a node. text implies that the tag is a text node.
|
22 |
+
* This allows for us to find tags based on the text they contain.
|
23 |
+
* Create find_ancestor_tag to see if a tag is - at any level - inside of another specific tag.
|
24 |
+
* Paperg: added parse_charset so that we know about the character set of the source document.
|
25 |
+
* NOTE: If the user's system has a routine called get_last_retrieve_url_contents_content_type availalbe, we will assume it's returning the content-type header from the
|
26 |
+
* last transfer or curl_exec, and we will parse that and use it in preference to any other method of charset detection.
|
27 |
+
*
|
28 |
+
* Found infinite loop in the case of broken html in restore_noise. Rewrote to protect from that.
|
29 |
+
* PaperG (John Schlick) Added get_display_size for "IMG" tags.
|
30 |
+
*
|
31 |
+
* Licensed under The MIT License
|
32 |
+
* Redistributions of files must retain the above copyright notice.
|
33 |
+
*
|
34 |
+
* @author S.C. Chen <me578022@gmail.com>
|
35 |
+
* @author John Schlick
|
36 |
+
* @author Rus Carroll
|
37 |
+
* @version 1.5 ($Rev: 210 $)
|
38 |
+
* @package PlaceLocalInclude
|
39 |
+
* @subpackage simple_html_dom
|
40 |
+
*/
|
41 |
+
|
42 |
+
/**
|
43 |
+
* All of the Defines for the classes below.
|
44 |
+
* @author S.C. Chen <me578022@gmail.com>
|
45 |
+
*/
|
46 |
+
define('HDOM_TYPE_ELEMENT', 1);
|
47 |
+
define('HDOM_TYPE_COMMENT', 2);
|
48 |
+
define('HDOM_TYPE_TEXT', 3);
|
49 |
+
define('HDOM_TYPE_ENDTAG', 4);
|
50 |
+
define('HDOM_TYPE_ROOT', 5);
|
51 |
+
define('HDOM_TYPE_UNKNOWN', 6);
|
52 |
+
define('HDOM_QUOTE_DOUBLE', 0);
|
53 |
+
define('HDOM_QUOTE_SINGLE', 1);
|
54 |
+
define('HDOM_QUOTE_NO', 3);
|
55 |
+
define('HDOM_INFO_BEGIN', 0);
|
56 |
+
define('HDOM_INFO_END', 1);
|
57 |
+
define('HDOM_INFO_QUOTE', 2);
|
58 |
+
define('HDOM_INFO_SPACE', 3);
|
59 |
+
define('HDOM_INFO_TEXT', 4);
|
60 |
+
define('HDOM_INFO_INNER', 5);
|
61 |
+
define('HDOM_INFO_OUTER', 6);
|
62 |
+
define('HDOM_INFO_ENDSPACE',7);
|
63 |
+
// helper functions
|
64 |
+
// -----------------------------------------------------------------------------
|
65 |
+
// get html dom from file
|
66 |
+
// $maxlen is defined in the code as PHP_STREAM_COPY_ALL which is defined as -1.
|
67 |
+
function file_get_html($url, $use_include_path = false, $context=null, $offset = -1, $maxLen=-1, $lowercase = true, $forceTagsClosed=true, $stripRN=true)
|
68 |
+
{
|
69 |
+
// We DO force the tags to be terminated.
|
70 |
+
$dom = new simple_html_dom(null, $lowercase, $forceTagsClosed, $stripRN, $defaultBRText, $defaultSpanText);
|
71 |
+
// For sourceforge users: uncomment the next line and comment the retreive_url_contents line 2 lines down if it is not already done.
|
72 |
+
$contents = file_get_contents($url, $use_include_path, $context, $offset);
|
73 |
+
// Paperg - use our own mechanism for getting the contents as we want to control the timeout.
|
74 |
+
//$contents = retrieve_url_contents($url);
|
75 |
+
if (empty($contents))
|
76 |
+
{
|
77 |
+
return false;
|
78 |
+
}
|
79 |
+
// The second parameter can force the selectors to all be lowercase.
|
80 |
+
$dom->load($contents, $lowercase, $stripRN);
|
81 |
+
return $dom;
|
82 |
+
}
|
83 |
+
|
84 |
+
// get html dom from string
|
85 |
+
function str_get_html($str, $lowercase=true, $forceTagsClosed=true, $stripRN=true)
|
86 |
+
{
|
87 |
+
$dom = new simple_html_dom(null, $lowercase, $forceTagsClosed, $stripRN);
|
88 |
+
if (empty($str))
|
89 |
+
{
|
90 |
+
$dom->clear();
|
91 |
+
return false;
|
92 |
+
}
|
93 |
+
$dom->load($str, $lowercase, $stripRN);
|
94 |
+
return $dom;
|
95 |
+
}
|
96 |
+
|
97 |
+
// dump html dom tree
|
98 |
+
function dump_html_tree($node, $show_attr=true, $deep=0)
|
99 |
+
{
|
100 |
+
$node->dump($node);
|
101 |
+
}
|
102 |
+
|
103 |
+
|
104 |
+
/**
|
105 |
+
* simple html dom node
|
106 |
+
* PaperG - added ability for "find" routine to lowercase the value of the selector.
|
107 |
+
* PaperG - added $tag_start to track the start position of the tag in the total byte index
|
108 |
+
*
|
109 |
+
* @package PlaceLocalInclude
|
110 |
+
*/
|
111 |
+
class simple_html_dom_node
|
112 |
+
{
|
113 |
+
public $nodetype = HDOM_TYPE_TEXT;
|
114 |
+
public $tag = 'text';
|
115 |
+
public $attr = array();
|
116 |
+
public $children = array();
|
117 |
+
public $nodes = array();
|
118 |
+
public $parent = null;
|
119 |
+
// The "info" array - see HDOM_INFO_... for what each element contains.
|
120 |
+
public $_ = array();
|
121 |
+
public $tag_start = 0;
|
122 |
+
private $dom = null;
|
123 |
+
|
124 |
+
function __construct($dom)
|
125 |
+
{
|
126 |
+
$this->dom = $dom;
|
127 |
+
$dom->nodes[] = $this;
|
128 |
+
}
|
129 |
+
|
130 |
+
function __destruct()
|
131 |
+
{
|
132 |
+
$this->clear();
|
133 |
+
}
|
134 |
+
|
135 |
+
function __toString()
|
136 |
+
{
|
137 |
+
return $this->outertext();
|
138 |
+
}
|
139 |
+
|
140 |
+
// clean up memory due to php5 circular references memory leak...
|
141 |
+
function clear()
|
142 |
+
{
|
143 |
+
$this->dom = null;
|
144 |
+
$this->nodes = null;
|
145 |
+
$this->parent = null;
|
146 |
+
$this->children = null;
|
147 |
+
}
|
148 |
+
|
149 |
+
// dump node's tree
|
150 |
+
function dump($show_attr=true, $deep=0)
|
151 |
+
{
|
152 |
+
$lead = str_repeat(' ', $deep);
|
153 |
+
|
154 |
+
echo $lead.$this->tag;
|
155 |
+
if ($show_attr && count($this->attr)>0)
|
156 |
+
{
|
157 |
+
echo '(';
|
158 |
+
foreach ($this->attr as $k=>$v)
|
159 |
+
echo "[$k]=>\"".$this->$k.'", ';
|
160 |
+
echo ')';
|
161 |
+
}
|
162 |
+
echo "\n";
|
163 |
+
|
164 |
+
if ($this->nodes)
|
165 |
+
{
|
166 |
+
foreach ($this->nodes as $c)
|
167 |
+
{
|
168 |
+
$c->dump($show_attr, $deep+1);
|
169 |
+
}
|
170 |
+
}
|
171 |
+
}
|
172 |
+
|
173 |
+
|
174 |
+
// Debugging function to dump a single dom node with a bunch of information about it.
|
175 |
+
function dump_node($echo=true)
|
176 |
+
{
|
177 |
+
|
178 |
+
$string = $this->tag;
|
179 |
+
if (count($this->attr)>0)
|
180 |
+
{
|
181 |
+
$string .= '(';
|
182 |
+
foreach ($this->attr as $k=>$v)
|
183 |
+
{
|
184 |
+
$string .= "[$k]=>\"".$this->$k.'", ';
|
185 |
+
}
|
186 |
+
$string .= ')';
|
187 |
+
}
|
188 |
+
if (count($this->_)>0)
|
189 |
+
{
|
190 |
+
$string .= ' $_ (';
|
191 |
+
foreach ($this->_ as $k=>$v)
|
192 |
+
{
|
193 |
+
if (is_array($v))
|
194 |
+
{
|
195 |
+
$string .= "[$k]=>(";
|
196 |
+
foreach ($v as $k2=>$v2)
|
197 |
+
{
|
198 |
+
$string .= "[$k2]=>\"".$v2.'", ';
|
199 |
+
}
|
200 |
+
$string .= ")";
|
201 |
+
} else {
|
202 |
+
$string .= "[$k]=>\"".$v.'", ';
|
203 |
+
}
|
204 |
+
}
|
205 |
+
$string .= ")";
|
206 |
+
}
|
207 |
+
|
208 |
+
if (isset($this->text))
|
209 |
+
{
|
210 |
+
$string .= " text: (" . $this->text . ")";
|
211 |
+
}
|
212 |
+
|
213 |
+
$string .= " HDOM_INNER_INFO: '";
|
214 |
+
if (isset($node->_[HDOM_INFO_INNER]))
|
215 |
+
{
|
216 |
+
$string .= $node->_[HDOM_INFO_INNER] . "'";
|
217 |
+
}
|
218 |
+
else
|
219 |
+
{
|
220 |
+
$string .= ' NULL ';
|
221 |
+
}
|
222 |
+
|
223 |
+
$string .= " children: " . count($this->children);
|
224 |
+
$string .= " nodes: " . count($this->nodes);
|
225 |
+
$string .= " tag_start: " . $this->tag_start;
|
226 |
+
$string .= "\n";
|
227 |
+
|
228 |
+
if ($echo)
|
229 |
+
{
|
230 |
+
echo $string;
|
231 |
+
return;
|
232 |
+
}
|
233 |
+
else
|
234 |
+
{
|
235 |
+
return $string;
|
236 |
+
}
|
237 |
+
}
|
238 |
+
|
239 |
+
// returns the parent of node
|
240 |
+
// If a node is passed in, it will reset the parent of the current node to that one.
|
241 |
+
function parent($parent=null)
|
242 |
+
{
|
243 |
+
// I am SURE that this doesn't work properly.
|
244 |
+
// It fails to unset the current node from it's current parents nodes or children list first.
|
245 |
+
if ($parent !== null)
|
246 |
+
{
|
247 |
+
$this->parent = $parent;
|
248 |
+
$this->parent->nodes[] = $this;
|
249 |
+
$this->parent->children[] = $this;
|
250 |
+
}
|
251 |
+
|
252 |
+
return $this->parent;
|
253 |
+
}
|
254 |
+
|
255 |
+
// verify that node has children
|
256 |
+
function has_child()
|
257 |
+
{
|
258 |
+
return !empty($this->children);
|
259 |
+
}
|
260 |
+
|
261 |
+
// returns children of node
|
262 |
+
function children($idx=-1)
|
263 |
+
{
|
264 |
+
if ($idx===-1)
|
265 |
+
{
|
266 |
+
return $this->children;
|
267 |
+
}
|
268 |
+
if (isset($this->children[$idx]))
|
269 |
+
{
|
270 |
+
return $this->children[$idx];
|
271 |
+
}
|
272 |
+
return null;
|
273 |
+
}
|
274 |
+
|
275 |
+
// returns the first child of node
|
276 |
+
function first_child()
|
277 |
+
{
|
278 |
+
if (count($this->children)>0)
|
279 |
+
{
|
280 |
+
return $this->children[0];
|
281 |
+
}
|
282 |
+
return null;
|
283 |
+
}
|
284 |
+
|
285 |
+
// returns the last child of node
|
286 |
+
function last_child()
|
287 |
+
{
|
288 |
+
if (($count=count($this->children))>0)
|
289 |
+
{
|
290 |
+
return $this->children[$count-1];
|
291 |
+
}
|
292 |
+
return null;
|
293 |
+
}
|
294 |
+
|
295 |
+
// returns the next sibling of node
|
296 |
+
function next_sibling()
|
297 |
+
{
|
298 |
+
if ($this->parent===null)
|
299 |
+
{
|
300 |
+
return null;
|
301 |
+
}
|
302 |
+
|
303 |
+
$idx = 0;
|
304 |
+
$count = count($this->parent->children);
|
305 |
+
while ($idx<$count && $this!==$this->parent->children[$idx])
|
306 |
+
{
|
307 |
+
++$idx;
|
308 |
+
}
|
309 |
+
if (++$idx>=$count)
|
310 |
+
{
|
311 |
+
return null;
|
312 |
+
}
|
313 |
+
return $this->parent->children[$idx];
|
314 |
+
}
|
315 |
+
|
316 |
+
// returns the previous sibling of node
|
317 |
+
function prev_sibling()
|
318 |
+
{
|
319 |
+
if ($this->parent===null) return null;
|
320 |
+
$idx = 0;
|
321 |
+
$count = count($this->parent->children);
|
322 |
+
while ($idx<$count && $this!==$this->parent->children[$idx])
|
323 |
+
++$idx;
|
324 |
+
if (--$idx<0) return null;
|
325 |
+
return $this->parent->children[$idx];
|
326 |
+
}
|
327 |
+
|
328 |
+
// function to locate a specific ancestor tag in the path to the root.
|
329 |
+
function find_ancestor_tag($tag)
|
330 |
+
{
|
331 |
+
global $debug_object;
|
332 |
+
if (is_object($debug_object)) { $debug_object->debug_log_entry(1); }
|
333 |
+
|
334 |
+
// Start by including ourselves in the comparison.
|
335 |
+
$returnDom = $this;
|
336 |
+
|
337 |
+
while (!is_null($returnDom))
|
338 |
+
{
|
339 |
+
if (is_object($debug_object)) { $debug_object->debug_log(2, "Current tag is: " . $returnDom->tag); }
|
340 |
+
|
341 |
+
if ($returnDom->tag == $tag)
|
342 |
+
{
|
343 |
+
break;
|
344 |
+
}
|
345 |
+
$returnDom = $returnDom->parent;
|
346 |
+
}
|
347 |
+
return $returnDom;
|
348 |
+
}
|
349 |
+
|
350 |
+
// get dom node's inner html
|
351 |
+
function innertext()
|
352 |
+
{
|
353 |
+
if (isset($this->_[HDOM_INFO_INNER])) return $this->_[HDOM_INFO_INNER];
|
354 |
+
if (isset($this->_[HDOM_INFO_TEXT])) return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]);
|
355 |
+
|
356 |
+
$ret = '';
|
357 |
+
foreach ($this->nodes as $n)
|
358 |
+
$ret .= $n->outertext();
|
359 |
+
return $ret;
|
360 |
+
}
|
361 |
+
|
362 |
+
// get dom node's outer text (with tag)
|
363 |
+
function outertext()
|
364 |
+
{
|
365 |
+
global $debug_object;
|
366 |
+
if (is_object($debug_object))
|
367 |
+
{
|
368 |
+
$text = '';
|
369 |
+
if ($this->tag == 'text')
|
370 |
+
{
|
371 |
+
if (!empty($this->text))
|
372 |
+
{
|
373 |
+
$text = " with text: " . $this->text;
|
374 |
+
}
|
375 |
+
}
|
376 |
+
$debug_object->debug_log(1, 'Innertext of tag: ' . $this->tag . $text);
|
377 |
+
}
|
378 |
+
|
379 |
+
if ($this->tag==='root') return $this->innertext();
|
380 |
+
|
381 |
+
// trigger callback
|
382 |
+
if ($this->dom && $this->dom->callback!==null)
|
383 |
+
{
|
384 |
+
call_user_func_array($this->dom->callback, array($this));
|
385 |
+
}
|
386 |
+
|
387 |
+
if (isset($this->_[HDOM_INFO_OUTER])) return $this->_[HDOM_INFO_OUTER];
|
388 |
+
if (isset($this->_[HDOM_INFO_TEXT])) return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]);
|
389 |
+
|
390 |
+
// render begin tag
|
391 |
+
if ($this->dom && $this->dom->nodes[$this->_[HDOM_INFO_BEGIN]])
|
392 |
+
{
|
393 |
+
$ret = $this->dom->nodes[$this->_[HDOM_INFO_BEGIN]]->makeup();
|
394 |
+
} else {
|
395 |
+
$ret = "";
|
396 |
+
}
|
397 |
+
|
398 |
+
// render inner text
|
399 |
+
if (isset($this->_[HDOM_INFO_INNER]))
|
400 |
+
{
|
401 |
+
// If it's a br tag... don't return the HDOM_INNER_INFO that we may or may not have added.
|
402 |
+
if ($this->tag != "br")
|
403 |
+
{
|
404 |
+
$ret .= $this->_[HDOM_INFO_INNER];
|
405 |
+
}
|
406 |
+
} else {
|
407 |
+
if ($this->nodes)
|
408 |
+
{
|
409 |
+
foreach ($this->nodes as $n)
|
410 |
+
{
|
411 |
+
$ret .= $this->convert_text($n->outertext());
|
412 |
+
}
|
413 |
+
}
|
414 |
+
}
|
415 |
+
|
416 |
+
// render end tag
|
417 |
+
if (isset($this->_[HDOM_INFO_END]) && $this->_[HDOM_INFO_END]!=0)
|
418 |
+
$ret .= '</'.$this->tag.'>';
|
419 |
+
return $ret;
|
420 |
+
}
|
421 |
+
|
422 |
+
// get dom node's plain text
|
423 |
+
function text()
|
424 |
+
{
|
425 |
+
if (isset($this->_[HDOM_INFO_INNER])) return $this->_[HDOM_INFO_INNER];
|
426 |
+
switch ($this->nodetype)
|
427 |
+
{
|
428 |
+
case HDOM_TYPE_TEXT: return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]);
|
429 |
+
case HDOM_TYPE_COMMENT: return '';
|
430 |
+
case HDOM_TYPE_UNKNOWN: return '';
|
431 |
+
}
|
432 |
+
if (strcasecmp($this->tag, 'script')===0) return '';
|
433 |
+
if (strcasecmp($this->tag, 'style')===0) return '';
|
434 |
+
|
435 |
+
$ret = '';
|
436 |
+
// In rare cases, (always node type 1 or HDOM_TYPE_ELEMENT - observed for some span tags, and some p tags) $this->nodes is set to NULL.
|
437 |
+
// NOTE: This indicates that there is a problem where it's set to NULL without a clear happening.
|
438 |
+
// WHY is this happening?
|
439 |
+
if (!is_null($this->nodes))
|
440 |
+
{
|
441 |
+
foreach ($this->nodes as $n)
|
442 |
+
{
|
443 |
+
$ret .= $this->convert_text($n->text());
|
444 |
+
}
|
445 |
+
|
446 |
+
// If this node is a span... add a space at the end of it so multiple spans don't run into each other. This is plaintext after all.
|
447 |
+
if ($this->tag == "span")
|
448 |
+
{
|
449 |
+
$ret .= $this->dom->default_span_text;
|
450 |
+
}
|
451 |
+
|
452 |
+
|
453 |
+
}
|
454 |
+
return $ret;
|
455 |
+
}
|
456 |
+
|
457 |
+
function xmltext()
|
458 |
+
{
|
459 |
+
$ret = $this->innertext();
|
460 |
+
$ret = str_ireplace('<![CDATA[', '', $ret);
|
461 |
+
$ret = str_replace(']]>', '', $ret);
|
462 |
+
return $ret;
|
463 |
+
}
|
464 |
+
|
465 |
+
// build node's text with tag
|
466 |
+
function makeup()
|
467 |
+
{
|
468 |
+
// text, comment, unknown
|
469 |
+
if (isset($this->_[HDOM_INFO_TEXT])) return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]);
|
470 |
+
|
471 |
+
$ret = '<'.$this->tag;
|
472 |
+
$i = -1;
|
473 |
+
|
474 |
+
foreach ($this->attr as $key=>$val)
|
475 |
+
{
|
476 |
+
++$i;
|
477 |
+
|
478 |
+
// skip removed attribute
|
479 |
+
if ($val===null || $val===false)
|
480 |
+
continue;
|
481 |
+
|
482 |
+
$ret .= $this->_[HDOM_INFO_SPACE][$i][0];
|
483 |
+
//no value attr: nowrap, checked selected...
|
484 |
+
if ($val===true)
|
485 |
+
$ret .= $key;
|
486 |
+
else {
|
487 |
+
switch ($this->_[HDOM_INFO_QUOTE][$i])
|
488 |
+
{
|
489 |
+
case HDOM_QUOTE_DOUBLE: $quote = '"'; break;
|
490 |
+
case HDOM_QUOTE_SINGLE: $quote = '\''; break;
|
491 |
+
default: $quote = '';
|
492 |
+
}
|
493 |
+
$ret .= $key.$this->_[HDOM_INFO_SPACE][$i][1].'='.$this->_[HDOM_INFO_SPACE][$i][2].$quote.$val.$quote;
|
494 |
+
}
|
495 |
+
}
|
496 |
+
$ret = $this->dom->restore_noise($ret);
|
497 |
+
return $ret . $this->_[HDOM_INFO_ENDSPACE] . '>';
|
498 |
+
}
|
499 |
+
|
500 |
+
// find elements by css selector
|
501 |
+
//PaperG - added ability for find to lowercase the value of the selector.
|
502 |
+
function find($selector, $idx=null, $lowercase=false)
|
503 |
+
{
|
504 |
+
$selectors = $this->parse_selector($selector);
|
505 |
+
if (($count=count($selectors))===0) return array();
|
506 |
+
$found_keys = array();
|
507 |
+
|
508 |
+
// find each selector
|
509 |
+
for ($c=0; $c<$count; ++$c)
|
510 |
+
{
|
511 |
+
// The change on the below line was documented on the sourceforge code tracker id 2788009
|
512 |
+
// used to be: if (($levle=count($selectors[0]))===0) return array();
|
513 |
+
if (($levle=count($selectors[$c]))===0) return array();
|
514 |
+
if (!isset($this->_[HDOM_INFO_BEGIN])) return array();
|
515 |
+
|
516 |
+
$head = array($this->_[HDOM_INFO_BEGIN]=>1);
|
517 |
+
|
518 |
+
// handle descendant selectors, no recursive!
|
519 |
+
for ($l=0; $l<$levle; ++$l)
|
520 |
+
{
|
521 |
+
$ret = array();
|
522 |
+
foreach ($head as $k=>$v)
|
523 |
+
{
|
524 |
+
$n = ($k===-1) ? $this->dom->root : $this->dom->nodes[$k];
|
525 |
+
//PaperG - Pass this optional parameter on to the seek function.
|
526 |
+
$n->seek($selectors[$c][$l], $ret, $lowercase);
|
527 |
+
}
|
528 |
+
$head = $ret;
|
529 |
+
}
|
530 |
+
|
531 |
+
foreach ($head as $k=>$v)
|
532 |
+
{
|
533 |
+
if (!isset($found_keys[$k]))
|
534 |
+
{
|
535 |
+
$found_keys[$k] = 1;
|
536 |
+
}
|
537 |
+
}
|
538 |
+
}
|
539 |
+
|
540 |
+
// sort keys
|
541 |
+
ksort($found_keys);
|
542 |
+
|
543 |
+
$found = array();
|
544 |
+
foreach ($found_keys as $k=>$v)
|
545 |
+
$found[] = $this->dom->nodes[$k];
|
546 |
+
|
547 |
+
// return nth-element or array
|
548 |
+
if (is_null($idx)) return $found;
|
549 |
+
else if ($idx<0) $idx = count($found) + $idx;
|
550 |
+
return (isset($found[$idx])) ? $found[$idx] : null;
|
551 |
+
}
|
552 |
+
|
553 |
+
// seek for given conditions
|
554 |
+
// PaperG - added parameter to allow for case insensitive testing of the value of a selector.
|
555 |
+
protected function seek($selector, &$ret, $lowercase=false)
|
556 |
+
{
|
557 |
+
global $debug_object;
|
558 |
+
if (is_object($debug_object)) { $debug_object->debug_log_entry(1); }
|
559 |
+
|
560 |
+
list($tag, $key, $val, $exp, $no_key) = $selector;
|
561 |
+
|
562 |
+
// xpath index
|
563 |
+
if ($tag && $key && is_numeric($key))
|
564 |
+
{
|
565 |
+
$count = 0;
|
566 |
+
foreach ($this->children as $c)
|
567 |
+
{
|
568 |
+
if ($tag==='*' || $tag===$c->tag) {
|
569 |
+
if (++$count==$key) {
|
570 |
+
$ret[$c->_[HDOM_INFO_BEGIN]] = 1;
|
571 |
+
return;
|
572 |
+
}
|
573 |
+
}
|
574 |
+
}
|
575 |
+
return;
|
576 |
+
}
|
577 |
+
|
578 |
+
$end = (!empty($this->_[HDOM_INFO_END])) ? $this->_[HDOM_INFO_END] : 0;
|
579 |
+
if ($end==0) {
|
580 |
+
$parent = $this->parent;
|
581 |
+
while (!isset($parent->_[HDOM_INFO_END]) && $parent!==null) {
|
582 |
+
$end -= 1;
|
583 |
+
$parent = $parent->parent;
|
584 |
+
}
|
585 |
+
$end += $parent->_[HDOM_INFO_END];
|
586 |
+
}
|
587 |
+
|
588 |
+
for ($i=$this->_[HDOM_INFO_BEGIN]+1; $i<$end; ++$i) {
|
589 |
+
$node = $this->dom->nodes[$i];
|
590 |
+
|
591 |
+
$pass = true;
|
592 |
+
|
593 |
+
if ($tag==='*' && !$key) {
|
594 |
+
if (in_array($node, $this->children, true))
|
595 |
+
$ret[$i] = 1;
|
596 |
+
continue;
|
597 |
+
}
|
598 |
+
|
599 |
+
// compare tag
|
600 |
+
if ($tag && $tag!=$node->tag && $tag!=='*') {$pass=false;}
|
601 |
+
// compare key
|
602 |
+
if ($pass && $key) {
|
603 |
+
if ($no_key) {
|
604 |
+
if (isset($node->attr[$key])) $pass=false;
|
605 |
+
} else {
|
606 |
+
if (($key != "plaintext") && !isset($node->attr[$key])) $pass=false;
|
607 |
+
}
|
608 |
+
}
|
609 |
+
// compare value
|
610 |
+
if ($pass && $key && $val && $val!=='*') {
|
611 |
+
// If they have told us that this is a "plaintext" search then we want the plaintext of the node - right?
|
612 |
+
if ($key == "plaintext") {
|
613 |
+
// $node->plaintext actually returns $node->text();
|
614 |
+
$nodeKeyValue = $node->text();
|
615 |
+
} else {
|
616 |
+
// this is a normal search, we want the value of that attribute of the tag.
|
617 |
+
$nodeKeyValue = $node->attr[$key];
|
618 |
+
}
|
619 |
+
if (is_object($debug_object)) {$debug_object->debug_log(2, "testing node: " . $node->tag . " for attribute: " . $key . $exp . $val . " where nodes value is: " . $nodeKeyValue);}
|
620 |
+
|
621 |
+
//PaperG - If lowercase is set, do a case insensitive test of the value of the selector.
|
622 |
+
if ($lowercase) {
|
623 |
+
$check = $this->match($exp, strtolower($val), strtolower($nodeKeyValue));
|
624 |
+
} else {
|
625 |
+
$check = $this->match($exp, $val, $nodeKeyValue);
|
626 |
+
}
|
627 |
+
if (is_object($debug_object)) {$debug_object->debug_log(2, "after match: " . ($check ? "true" : "false"));}
|
628 |
+
|
629 |
+
// handle multiple class
|
630 |
+
if (!$check && strcasecmp($key, 'class')===0) {
|
631 |
+
foreach (explode(' ',$node->attr[$key]) as $k) {
|
632 |
+
// Without this, there were cases where leading, trailing, or double spaces lead to our comparing blanks - bad form.
|
633 |
+
if (!empty($k)) {
|
634 |
+
if ($lowercase) {
|
635 |
+
$check = $this->match($exp, strtolower($val), strtolower($k));
|
636 |
+
} else {
|
637 |
+
$check = $this->match($exp, $val, $k);
|
638 |
+
}
|
639 |
+
if ($check) break;
|
640 |
+
}
|
641 |
+
}
|
642 |
+
}
|
643 |
+
if (!$check) $pass = false;
|
644 |
+
}
|
645 |
+
if ($pass) $ret[$i] = 1;
|
646 |
+
unset($node);
|
647 |
+
}
|
648 |
+
// It's passed by reference so this is actually what this function returns.
|
649 |
+
if (is_object($debug_object)) {$debug_object->debug_log(1, "EXIT - ret: ", $ret);}
|
650 |
+
}
|
651 |
+
|
652 |
+
protected function match($exp, $pattern, $value) {
|
653 |
+
global $debug_object;
|
654 |
+
if (is_object($debug_object)) {$debug_object->debug_log_entry(1);}
|
655 |
+
|
656 |
+
switch ($exp) {
|
657 |
+
case '=':
|
658 |
+
return ($value===$pattern);
|
659 |
+
case '!=':
|
660 |
+
return ($value!==$pattern);
|
661 |
+
case '^=':
|
662 |
+
return preg_match("/^".preg_quote($pattern,'/')."/", $value);
|
663 |
+
case '$=':
|
664 |
+
return preg_match("/".preg_quote($pattern,'/')."$/", $value);
|
665 |
+
case '*=':
|
666 |
+
if ($pattern[0]=='/') {
|
667 |
+
return preg_match($pattern, $value);
|
668 |
+
}
|
669 |
+
return preg_match("/".$pattern."/i", $value);
|
670 |
+
}
|
671 |
+
return false;
|
672 |
+
}
|
673 |
+
|
674 |
+
protected function parse_selector($selector_string) {
|
675 |
+
global $debug_object;
|
676 |
+
if (is_object($debug_object)) {$debug_object->debug_log_entry(1);}
|
677 |
+
|
678 |
+
// pattern of CSS selectors, modified from mootools
|
679 |
+
// Paperg: Add the colon to the attrbute, so that it properly finds <tag attr:ibute="something" > like google does.
|
680 |
+
// Note: if you try to look at this attribute, yo MUST use getAttribute since $dom->x:y will fail the php syntax check.
|
681 |
+
// Notice the \[ starting the attbute? and the @? following? This implies that an attribute can begin with an @ sign that is not captured.
|
682 |
+
// This implies that an html attribute specifier may start with an @ sign that is NOT captured by the expression.
|
683 |
+
// farther study is required to determine of this should be documented or removed.
|
684 |
+
// $pattern = "/([\w-:\*]*)(?:\#([\w-]+)|\.([\w-]+))?(?:\[@?(!?[\w-]+)(?:([!*^$]?=)[\"']?(.*?)[\"']?)?\])?([\/, ]+)/is";
|
685 |
+
$pattern = "/([\w-:\*]*)(?:\#([\w-]+)|\.([\w-]+))?(?:\[@?(!?[\w-:]+)(?:([!*^$]?=)[\"']?(.*?)[\"']?)?\])?([\/, ]+)/is";
|
686 |
+
preg_match_all($pattern, trim($selector_string).' ', $matches, PREG_SET_ORDER);
|
687 |
+
if (is_object($debug_object)) {$debug_object->debug_log(2, "Matches Array: ", $matches);}
|
688 |
+
|
689 |
+
$selectors = array();
|
690 |
+
$result = array();
|
691 |
+
//print_r($matches);
|
692 |
+
|
693 |
+
foreach ($matches as $m) {
|
694 |
+
$m[0] = trim($m[0]);
|
695 |
+
if ($m[0]==='' || $m[0]==='/' || $m[0]==='//') continue;
|
696 |
+
// for browser generated xpath
|
697 |
+
if ($m[1]==='tbody') continue;
|
698 |
+
|
699 |
+
list($tag, $key, $val, $exp, $no_key) = array($m[1], null, null, '=', false);
|
700 |
+
if (!empty($m[2])) {$key='id'; $val=$m[2];}
|
701 |
+
if (!empty($m[3])) {$key='class'; $val=$m[3];}
|
702 |
+
if (!empty($m[4])) {$key=$m[4];}
|
703 |
+
if (!empty($m[5])) {$exp=$m[5];}
|
704 |
+
if (!empty($m[6])) {$val=$m[6];}
|
705 |
+
|
706 |
+
// convert to lowercase
|
707 |
+
if ($this->dom->lowercase) {$tag=strtolower($tag); $key=strtolower($key);}
|
708 |
+
//elements that do NOT have the specified attribute
|
709 |
+
if (isset($key[0]) && $key[0]==='!') {$key=substr($key, 1); $no_key=true;}
|
710 |
+
|
711 |
+
$result[] = array($tag, $key, $val, $exp, $no_key);
|
712 |
+
if (trim($m[7])===',') {
|
713 |
+
$selectors[] = $result;
|
714 |
+
$result = array();
|
715 |
+
}
|
716 |
+
}
|
717 |
+
if (count($result)>0)
|
718 |
+
$selectors[] = $result;
|
719 |
+
return $selectors;
|
720 |
+
}
|
721 |
+
|
722 |
+
function __get($name)
|
723 |
+
{
|
724 |
+
if (isset($this->attr[$name]))
|
725 |
+
{
|
726 |
+
return $this->convert_text($this->attr[$name]);
|
727 |
+
}
|
728 |
+
switch ($name)
|
729 |
+
{
|
730 |
+
case 'outertext': return $this->outertext();
|
731 |
+
case 'innertext': return $this->innertext();
|
732 |
+
case 'plaintext': return $this->text();
|
733 |
+
case 'xmltext': return $this->xmltext();
|
734 |
+
default: return array_key_exists($name, $this->attr);
|
735 |
+
}
|
736 |
+
}
|
737 |
+
|
738 |
+
function __set($name, $value)
|
739 |
+
{
|
740 |
+
global $debug_object;
|
741 |
+
if (is_object($debug_object)) {$debug_object->debug_log_entry(1);}
|
742 |
+
|
743 |
+
switch ($name)
|
744 |
+
{
|
745 |
+
case 'outertext': return $this->_[HDOM_INFO_OUTER] = $value;
|
746 |
+
case 'innertext':
|
747 |
+
if (isset($this->_[HDOM_INFO_TEXT])) return $this->_[HDOM_INFO_TEXT] = $value;
|
748 |
+
return $this->_[HDOM_INFO_INNER] = $value;
|
749 |
+
}
|
750 |
+
if (!isset($this->attr[$name]))
|
751 |
+
{
|
752 |
+
$this->_[HDOM_INFO_SPACE][] = array(' ', '', '');
|
753 |
+
$this->_[HDOM_INFO_QUOTE][] = HDOM_QUOTE_DOUBLE;
|
754 |
+
}
|
755 |
+
$this->attr[$name] = $value;
|
756 |
+
}
|
757 |
+
|
758 |
+
function __isset($name)
|
759 |
+
{
|
760 |
+
switch ($name)
|
761 |
+
{
|
762 |
+
case 'outertext': return true;
|
763 |
+
case 'innertext': return true;
|
764 |
+
case 'plaintext': return true;
|
765 |
+
}
|
766 |
+
//no value attr: nowrap, checked selected...
|
767 |
+
return (array_key_exists($name, $this->attr)) ? true : isset($this->attr[$name]);
|
768 |
+
}
|
769 |
+
|
770 |
+
function __unset($name) {
|
771 |
+
if (isset($this->attr[$name]))
|
772 |
+
unset($this->attr[$name]);
|
773 |
+
}
|
774 |
+
|
775 |
+
// PaperG - Function to convert the text from one character set to another if the two sets are not the same.
|
776 |
+
function convert_text($text)
|
777 |
+
{
|
778 |
+
global $debug_object;
|
779 |
+
if (is_object($debug_object)) {$debug_object->debug_log_entry(1);}
|
780 |
+
|
781 |
+
$converted_text = $text;
|
782 |
+
|
783 |
+
$sourceCharset = "";
|
784 |
+
$targetCharset = "";
|
785 |
+
|
786 |
+
if ($this->dom)
|
787 |
+
{
|
788 |
+
$sourceCharset = strtoupper($this->dom->_charset);
|
789 |
+
$targetCharset = strtoupper($this->dom->_target_charset);
|
790 |
+
}
|
791 |
+
if (is_object($debug_object)) {$debug_object->debug_log(3, "source charset: " . $sourceCharset . " target charaset: " . $targetCharset);}
|
792 |
+
|
793 |
+
if (!empty($sourceCharset) && !empty($targetCharset) && (strcasecmp($sourceCharset, $targetCharset) != 0))
|
794 |
+
{
|
795 |
+
// Check if the reported encoding could have been incorrect and the text is actually already UTF-8
|
796 |
+
if ((strcasecmp($targetCharset, 'UTF-8') == 0) && ($this->is_utf8($text)))
|
797 |
+
{
|
798 |
+
$converted_text = $text;
|
799 |
+
}
|
800 |
+
else
|
801 |
+
{
|
802 |
+
$converted_text = iconv($sourceCharset, $targetCharset, $text);
|
803 |
+
}
|
804 |
+
}
|
805 |
+
|
806 |
+
// Lets make sure that we don't have that silly BOM issue with any of the utf-8 text we output.
|
807 |
+
if ($targetCharset == 'UTF-8')
|
808 |
+
{
|
809 |
+
if (substr($converted_text, 0, 3) == "\xef\xbb\xbf")
|
810 |
+
{
|
811 |
+
$converted_text = substr($converted_text, 3);
|
812 |
+
}
|
813 |
+
if (substr($converted_text, -3) == "\xef\xbb\xbf")
|
814 |
+
{
|
815 |
+
$converted_text = substr($converted_text, 0, -3);
|
816 |
+
}
|
817 |
+
}
|
818 |
+
|
819 |
+
return $converted_text;
|
820 |
+
}
|
821 |
+
|
822 |
+
/**
|
823 |
+
* Returns true if $string is valid UTF-8 and false otherwise.
|
824 |
+
*
|
825 |
+
* @param mixed $str String to be tested
|
826 |
+
* @return boolean
|
827 |
+
*/
|
828 |
+
static function is_utf8($str)
|
829 |
+
{
|
830 |
+
$c=0; $b=0;
|
831 |
+
$bits=0;
|
832 |
+
$len=strlen($str);
|
833 |
+
for($i=0; $i<$len; $i++)
|
834 |
+
{
|
835 |
+
$c=ord($str[$i]);
|
836 |
+
if($c > 128)
|
837 |
+
{
|
838 |
+
if(($c >= 254)) return false;
|
839 |
+
elseif($c >= 252) $bits=6;
|
840 |
+
elseif($c >= 248) $bits=5;
|
841 |
+
elseif($c >= 240) $bits=4;
|
842 |
+
elseif($c >= 224) $bits=3;
|
843 |
+
elseif($c >= 192) $bits=2;
|
844 |
+
else return false;
|
845 |
+
if(($i+$bits) > $len) return false;
|
846 |
+
while($bits > 1)
|
847 |
+
{
|
848 |
+
$i++;
|
849 |
+
$b=ord($str[$i]);
|
850 |
+
if($b < 128 || $b > 191) return false;
|
851 |
+
$bits--;
|
852 |
+
}
|
853 |
+
}
|
854 |
+
}
|
855 |
+
return true;
|
856 |
+
}
|
857 |
+
/*
|
858 |
+
function is_utf8($string)
|
859 |
+
{
|
860 |
+
//this is buggy
|
861 |
+
return (utf8_encode(utf8_decode($string)) == $string);
|
862 |
+
}
|
863 |
+
*/
|
864 |
+
|
865 |
+
/**
|
866 |
+
* Function to try a few tricks to determine the displayed size of an img on the page.
|
867 |
+
* NOTE: This will ONLY work on an IMG tag. Returns FALSE on all other tag types.
|
868 |
+
*
|
869 |
+
* @author John Schlick
|
870 |
+
* @version April 19 2012
|
871 |
+
* @return array an array containing the 'height' and 'width' of the image on the page or -1 if we can't figure it out.
|
872 |
+
*/
|
873 |
+
function get_display_size()
|
874 |
+
{
|
875 |
+
global $debug_object;
|
876 |
+
|
877 |
+
$width = -1;
|
878 |
+
$height = -1;
|
879 |
+
|
880 |
+
if ($this->tag !== 'img')
|
881 |
+
{
|
882 |
+
return false;
|
883 |
+
}
|
884 |
+
|
885 |
+
// See if there is aheight or width attribute in the tag itself.
|
886 |
+
if (isset($this->attr['width']))
|
887 |
+
{
|
888 |
+
$width = $this->attr['width'];
|
889 |
+
}
|
890 |
+
|
891 |
+
if (isset($this->attr['height']))
|
892 |
+
{
|
893 |
+
$height = $this->attr['height'];
|
894 |
+
}
|
895 |
+
|
896 |
+
// Now look for an inline style.
|
897 |
+
if (isset($this->attr['style']))
|
898 |
+
{
|
899 |
+
// Thanks to user gnarf from stackoverflow for this regular expression.
|
900 |
+
$attributes = array();
|
901 |
+
preg_match_all("/([\w-]+)\s*:\s*([^;]+)\s*;?/", $this->attr['style'], $matches, PREG_SET_ORDER);
|
902 |
+
foreach ($matches as $match) {
|
903 |
+
$attributes[$match[1]] = $match[2];
|
904 |
+
}
|
905 |
+
|
906 |
+
// If there is a width in the style attributes:
|
907 |
+
if (isset($attributes['width']) && $width == -1)
|
908 |
+
{
|
909 |
+
// check that the last two characters are px (pixels)
|
910 |
+
if (strtolower(substr($attributes['width'], -2)) == 'px')
|
911 |
+
{
|
912 |
+
$proposed_width = substr($attributes['width'], 0, -2);
|
913 |
+
// Now make sure that it's an integer and not something stupid.
|
914 |
+
if (filter_var($proposed_width, FILTER_VALIDATE_INT))
|
915 |
+
{
|
916 |
+
$width = $proposed_width;
|
917 |
+
}
|
918 |
+
}
|
919 |
+
}
|
920 |
+
|
921 |
+
// If there is a width in the style attributes:
|
922 |
+
if (isset($attributes['height']) && $height == -1)
|
923 |
+
{
|
924 |
+
// check that the last two characters are px (pixels)
|
925 |
+
if (strtolower(substr($attributes['height'], -2)) == 'px')
|
926 |
+
{
|
927 |
+
$proposed_height = substr($attributes['height'], 0, -2);
|
928 |
+
// Now make sure that it's an integer and not something stupid.
|
929 |
+
if (filter_var($proposed_height, FILTER_VALIDATE_INT))
|
930 |
+
{
|
931 |
+
$height = $proposed_height;
|
932 |
+
}
|
933 |
+
}
|
934 |
+
}
|
935 |
+
|
936 |
+
}
|
937 |
+
|
938 |
+
// Future enhancement:
|
939 |
+
// Look in the tag to see if there is a class or id specified that has a height or width attribute to it.
|
940 |
+
|
941 |
+
// Far future enhancement
|
942 |
+
// Look at all the parent tags of this image to see if they specify a class or id that has an img selector that specifies a height or width
|
943 |
+
// Note that in this case, the class or id will have the img subselector for it to apply to the image.
|
944 |
+
|
945 |
+
// ridiculously far future development
|
946 |
+
// If the class or id is specified in a SEPARATE css file thats not on the page, go get it and do what we were just doing for the ones on the page.
|
947 |
+
|
948 |
+
$result = array('height' => $height,
|
949 |
+
'width' => $width);
|
950 |
+
return $result;
|
951 |
+
}
|
952 |
+
|
953 |
+
// camel naming conventions
|
954 |
+
function getAllAttributes() {return $this->attr;}
|
955 |
+
function getAttribute($name) {return $this->__get($name);}
|
956 |
+
function setAttribute($name, $value) {$this->__set($name, $value);}
|
957 |
+
function hasAttribute($name) {return $this->__isset($name);}
|
958 |
+
function removeAttribute($name) {$this->__set($name, null);}
|
959 |
+
function getElementById($id) {return $this->find("#$id", 0);}
|
960 |
+
function getElementsById($id, $idx=null) {return $this->find("#$id", $idx);}
|
961 |
+
function getElementByTagName($name) {return $this->find($name, 0);}
|
962 |
+
function getElementsByTagName($name, $idx=null) {return $this->find($name, $idx);}
|
963 |
+
function parentNode() {return $this->parent();}
|
964 |
+
function childNodes($idx=-1) {return $this->children($idx);}
|
965 |
+
function firstChild() {return $this->first_child();}
|
966 |
+
function lastChild() {return $this->last_child();}
|
967 |
+
function nextSibling() {return $this->next_sibling();}
|
968 |
+
function previousSibling() {return $this->prev_sibling();}
|
969 |
+
function hasChildNodes() {return $this->has_child();}
|
970 |
+
function nodeName() {return $this->tag;}
|
971 |
+
function appendChild($node) {$node->parent($this); return $node;}
|
972 |
+
|
973 |
+
}
|
974 |
+
|
975 |
+
/**
|
976 |
+
* simple html dom parser
|
977 |
+
* Paperg - in the find routine: allow us to specify that we want case insensitive testing of the value of the selector.
|
978 |
+
* Paperg - change $size from protected to public so we can easily access it
|
979 |
+
* Paperg - added ForceTagsClosed in the constructor which tells us whether we trust the html or not. Default is to NOT trust it.
|
980 |
+
*
|
981 |
+
* @package PlaceLocalInclude
|
982 |
+
*/
|
983 |
+
class simple_html_dom
|
984 |
+
{
|
985 |
+
public $root = null;
|
986 |
+
public $nodes = array();
|
987 |
+
public $callback = null;
|
988 |
+
public $lowercase = false;
|
989 |
+
// Used to keep track of how large the text was when we started.
|
990 |
+
public $original_size;
|
991 |
+
public $size;
|
992 |
+
protected $pos;
|
993 |
+
protected $doc;
|
994 |
+
protected $char;
|
995 |
+
protected $cursor;
|
996 |
+
protected $parent;
|
997 |
+
protected $noise = array();
|
998 |
+
protected $token_blank = " \t\r\n";
|
999 |
+
protected $token_equal = ' =/>';
|
1000 |
+
protected $token_slash = " />\r\n\t";
|
1001 |
+
protected $token_attr = ' >';
|
1002 |
+
// Note that this is referenced by a child node, and so it needs to be public for that node to see this information.
|
1003 |
+
public $_charset = '';
|
1004 |
+
public $_target_charset = '';
|
1005 |
+
protected $default_br_text = "";
|
1006 |
+
public $default_span_text = "";
|
1007 |
+
|
1008 |
+
// use isset instead of in_array, performance boost about 30%...
|
1009 |
+
protected $self_closing_tags = array('img'=>1, 'br'=>1, 'input'=>1, 'meta'=>1, 'link'=>1, 'hr'=>1, 'base'=>1, 'embed'=>1, 'spacer'=>1);
|
1010 |
+
protected $block_tags = array('root'=>1, 'body'=>1, 'form'=>1, 'div'=>1, 'span'=>1, 'table'=>1);
|
1011 |
+
// Known sourceforge issue #2977341
|
1012 |
+
// B tags that are not closed cause us to return everything to the end of the document.
|
1013 |
+
protected $optional_closing_tags = array(
|
1014 |
+
'tr'=>array('tr'=>1, 'td'=>1, 'th'=>1),
|
1015 |
+
'th'=>array('th'=>1),
|
1016 |
+
'td'=>array('td'=>1),
|
1017 |
+
'li'=>array('li'=>1),
|
1018 |
+
'dt'=>array('dt'=>1, 'dd'=>1),
|
1019 |
+
'dd'=>array('dd'=>1, 'dt'=>1),
|
1020 |
+
'dl'=>array('dd'=>1, 'dt'=>1),
|
1021 |
+
'p'=>array('p'=>1),
|
1022 |
+
'nobr'=>array('nobr'=>1),
|
1023 |
+
'b'=>array('b'=>1),
|
1024 |
+
'option'=>array('option'=>1),
|
1025 |
+
);
|
1026 |
+
|
1027 |
+
function __construct($str=null, $lowercase=true, $forceTagsClosed=true, $stripRN=true)
|
1028 |
+
{
|
1029 |
+
if ($str)
|
1030 |
+
{
|
1031 |
+
if (preg_match("/^http:\/\//i",$str) || is_file($str))
|
1032 |
+
{
|
1033 |
+
$this->load_file($str);
|
1034 |
+
}
|
1035 |
+
else
|
1036 |
+
{
|
1037 |
+
$this->load($str, $lowercase, $stripRN, $defaultBRText, $defaultSpanText);
|
1038 |
+
}
|
1039 |
+
}
|
1040 |
+
// Forcing tags to be closed implies that we don't trust the html, but it can lead to parsing errors if we SHOULD trust the html.
|
1041 |
+
if (!$forceTagsClosed) {
|
1042 |
+
$this->optional_closing_array=array();
|
1043 |
+
}
|
1044 |
+
$this->_target_charset = 'UTF-8';
|
1045 |
+
}
|
1046 |
+
|
1047 |
+
function __destruct()
|
1048 |
+
{
|
1049 |
+
$this->clear();
|
1050 |
+
}
|
1051 |
+
|
1052 |
+
// load html from string
|
1053 |
+
function load($str, $lowercase=true, $stripRN=true)
|
1054 |
+
{
|
1055 |
+
global $debug_object;
|
1056 |
+
|
1057 |
+
// prepare
|
1058 |
+
$this->prepare($str, $lowercase, $stripRN, $defaultBRText, $defaultSpanText);
|
1059 |
+
// strip out cdata
|
1060 |
+
$this->remove_noise("'<!\[CDATA\[(.*?)\]\]>'is", true);
|
1061 |
+
// strip out comments
|
1062 |
+
$this->remove_noise("'<!--(.*?)-->'is");
|
1063 |
+
// Per sourceforge http://sourceforge.net/tracker/?func=detail&aid=2949097&group_id=218559&atid=1044037
|
1064 |
+
// Script tags removal now preceeds style tag removal.
|
1065 |
+
// strip out <script> tags
|
1066 |
+
$this->remove_noise("'<\s*script[^>]*[^/]>(.*?)<\s*/\s*script\s*>'is");
|
1067 |
+
$this->remove_noise("'<\s*script\s*>(.*?)<\s*/\s*script\s*>'is");
|
1068 |
+
// strip out <style> tags
|
1069 |
+
$this->remove_noise("'<\s*style[^>]*[^/]>(.*?)<\s*/\s*style\s*>'is");
|
1070 |
+
$this->remove_noise("'<\s*style\s*>(.*?)<\s*/\s*style\s*>'is");
|
1071 |
+
// strip out preformatted tags
|
1072 |
+
$this->remove_noise("'<\s*(?:code)[^>]*>(.*?)<\s*/\s*(?:code)\s*>'is");
|
1073 |
+
// strip out server side scripts
|
1074 |
+
$this->remove_noise("'(<\?)(.*?)(\?>)'s", true);
|
1075 |
+
// strip smarty scripts
|
1076 |
+
$this->remove_noise("'(\{\w)(.*?)(\})'s", true);
|
1077 |
+
|
1078 |
+
// parsing
|
1079 |
+
while ($this->parse());
|
1080 |
+
// end
|
1081 |
+
$this->root->_[HDOM_INFO_END] = $this->cursor;
|
1082 |
+
$this->parse_charset();
|
1083 |
+
|
1084 |
+
// make load function chainable
|
1085 |
+
return $this;
|
1086 |
+
|
1087 |
+
}
|
1088 |
+
|
1089 |
+
// load html from file
|
1090 |
+
function load_file()
|
1091 |
+
{
|
1092 |
+
$args = func_get_args();
|
1093 |
+
$this->load(call_user_func_array('file_get_contents', $args), true);
|
1094 |
+
// Throw an error if we can't properly load the dom.
|
1095 |
+
if (($error=error_get_last())!==null) {
|
1096 |
+
$this->clear();
|
1097 |
+
return false;
|
1098 |
+
}
|
1099 |
+
}
|
1100 |
+
|
1101 |
+
// set callback function
|
1102 |
+
function set_callback($function_name)
|
1103 |
+
{
|
1104 |
+
$this->callback = $function_name;
|
1105 |
+
}
|
1106 |
+
|
1107 |
+
// remove callback function
|
1108 |
+
function remove_callback()
|
1109 |
+
{
|
1110 |
+
$this->callback = null;
|
1111 |
+
}
|
1112 |
+
|
1113 |
+
// save dom as string
|
1114 |
+
function save($filepath='')
|
1115 |
+
{
|
1116 |
+
$ret = $this->root->innertext();
|
1117 |
+
if ($filepath!=='') file_put_contents($filepath, $ret, LOCK_EX);
|
1118 |
+
return $ret;
|
1119 |
+
}
|
1120 |
+
|
1121 |
+
// find dom node by css selector
|
1122 |
+
// Paperg - allow us to specify that we want case insensitive testing of the value of the selector.
|
1123 |
+
function find($selector, $idx=null, $lowercase=false)
|
1124 |
+
{
|
1125 |
+
return $this->root->find($selector, $idx, $lowercase);
|
1126 |
+
}
|
1127 |
+
|
1128 |
+
// clean up memory due to php5 circular references memory leak...
|
1129 |
+
function clear()
|
1130 |
+
{
|
1131 |
+
foreach ($this->nodes as $n) {$n->clear(); $n = null;}
|
1132 |
+
// This add next line is documented in the sourceforge repository. 2977248 as a fix for ongoing memory leaks that occur even with the use of clear.
|
1133 |
+
if (isset($this->children)) foreach ($this->children as $n) {$n->clear(); $n = null;}
|
1134 |
+
if (isset($this->parent)) {$this->parent->clear(); unset($this->parent);}
|
1135 |
+
if (isset($this->root)) {$this->root->clear(); unset($this->root);}
|
1136 |
+
unset($this->doc);
|
1137 |
+
unset($this->noise);
|
1138 |
+
}
|
1139 |
+
|
1140 |
+
function dump($show_attr=true)
|
1141 |
+
{
|
1142 |
+
$this->root->dump($show_attr);
|
1143 |
+
}
|
1144 |
+
|
1145 |
+
// prepare HTML data and init everything
|
1146 |
+
protected function prepare($str, $lowercase=true, $stripRN=true)
|
1147 |
+
{
|
1148 |
+
$this->clear();
|
1149 |
+
|
1150 |
+
// set the length of content before we do anything to it.
|
1151 |
+
$this->size = strlen($str);
|
1152 |
+
// Save the original size of the html that we got in. It might be useful to someone.
|
1153 |
+
$this->original_size = $this->size;
|
1154 |
+
|
1155 |
+
//before we save the string as the doc... strip out the \r \n's if we are told to.
|
1156 |
+
if ($stripRN) {
|
1157 |
+
$str = str_replace("\r", " ", $str);
|
1158 |
+
$str = str_replace("\n", " ", $str);
|
1159 |
+
|
1160 |
+
// set the length of content since we have changed it.
|
1161 |
+
$this->size = strlen($str);
|
1162 |
+
}
|
1163 |
+
|
1164 |
+
$this->doc = $str;
|
1165 |
+
$this->pos = 0;
|
1166 |
+
$this->cursor = 1;
|
1167 |
+
$this->noise = array();
|
1168 |
+
$this->nodes = array();
|
1169 |
+
$this->lowercase = $lowercase;
|
1170 |
+
$this->default_br_text = "\r\n";
|
1171 |
+
$this->default_span_text = " ";
|
1172 |
+
$this->root = new simple_html_dom_node($this);
|
1173 |
+
$this->root->tag = 'root';
|
1174 |
+
$this->root->_[HDOM_INFO_BEGIN] = -1;
|
1175 |
+
$this->root->nodetype = HDOM_TYPE_ROOT;
|
1176 |
+
$this->parent = $this->root;
|
1177 |
+
//if ($this->size>0) $this->char = $this->doc[0];
|
1178 |
+
}
|
1179 |
+
|
1180 |
+
// parse html content
|
1181 |
+
protected function parse()
|
1182 |
+
{
|
1183 |
+
if (($s = $this->copy_until_char('<'))==='')
|
1184 |
+
{
|
1185 |
+
return $this->read_tag();
|
1186 |
+
}
|
1187 |
+
|
1188 |
+
// text
|
1189 |
+
$node = new simple_html_dom_node($this);
|
1190 |
+
++$this->cursor;
|
1191 |
+
$node->_[HDOM_INFO_TEXT] = $s;
|
1192 |
+
$this->link_nodes($node, false);
|
1193 |
+
return true;
|
1194 |
+
}
|
1195 |
+
|
1196 |
+
// PAPERG - dkchou - added this to try to identify the character set of the page we have just parsed so we know better how to spit it out later.
|
1197 |
+
// NOTE: IF you provide a routine called get_last_retrieve_url_contents_content_type which returns the CURLINFO_CONTENT_TYPE from the last curl_exec
|
1198 |
+
// (or the content_type header from the last transfer), we will parse THAT, and if a charset is specified, we will use it over any other mechanism.
|
1199 |
+
protected function parse_charset()
|
1200 |
+
{
|
1201 |
+
global $debug_object;
|
1202 |
+
|
1203 |
+
$charset = null;
|
1204 |
+
|
1205 |
+
if (function_exists('get_last_retrieve_url_contents_content_type'))
|
1206 |
+
{
|
1207 |
+
$contentTypeHeader = get_last_retrieve_url_contents_content_type();
|
1208 |
+
$success = preg_match('/charset=(.+)/', $contentTypeHeader, $matches);
|
1209 |
+
if ($success)
|
1210 |
+
{
|
1211 |
+
$charset = $matches[1];
|
1212 |
+
if (is_object($debug_object)) {$debug_object->debug_log(2, 'header content-type found charset of: ' . $charset);}
|
1213 |
+
}
|
1214 |
+
|
1215 |
+
}
|
1216 |
+
|
1217 |
+
if (empty($charset))
|
1218 |
+
{
|
1219 |
+
$el = $this->root->find('meta[http-equiv=Content-Type]',0, true);
|
1220 |
+
if (!empty($el))
|
1221 |
+
{
|
1222 |
+
$fullvalue = $el->content;
|
1223 |
+
if (is_object($debug_object)) {$debug_object->debug_log(2, 'meta content-type tag found' . $fullvalue);}
|
1224 |
+
|
1225 |
+
if (!empty($fullvalue))
|
1226 |
+
{
|
1227 |
+
$success = preg_match('/charset=(.+)/i', $fullvalue, $matches);
|
1228 |
+
if ($success)
|
1229 |
+
{
|
1230 |
+
$charset = $matches[1];
|
1231 |
+
}
|
1232 |
+
else
|
1233 |
+
{
|
1234 |
+
// If there is a meta tag, and they don't specify the character set, research says that it's typically ISO-8859-1
|
1235 |
+
if (is_object($debug_object)) {$debug_object->debug_log(2, 'meta content-type tag couldn\'t be parsed. using iso-8859 default.');}
|
1236 |
+
$charset = 'ISO-8859-1';
|
1237 |
+
}
|
1238 |
+
}
|
1239 |
+
}
|
1240 |
+
}
|
1241 |
+
|
1242 |
+
// If we couldn't find a charset above, then lets try to detect one based on the text we got...
|
1243 |
+
if (empty($charset))
|
1244 |
+
{
|
1245 |
+
// Use this in case mb_detect_charset isn't installed/loaded on this machine.
|
1246 |
+
$charset = false;
|
1247 |
+
if (function_exists('mb_detect_encoding'))
|
1248 |
+
{
|
1249 |
+
// Have php try to detect the encoding from the text given to us.
|
1250 |
+
$charset = mb_detect_encoding($this->root->plaintext . "ascii", $encoding_list = array( "UTF-8", "CP1252" ) );
|
1251 |
+
if (is_object($debug_object)) {$debug_object->debug_log(2, 'mb_detect found: ' . $charset);}
|
1252 |
+
}
|
1253 |
+
|
1254 |
+
// and if this doesn't work... then we need to just wrongheadedly assume it's UTF-8 so that we can move on - cause this will usually give us most of what we need...
|
1255 |
+
if ($charset === false)
|
1256 |
+
{
|
1257 |
+
if (is_object($debug_object)) {$debug_object->debug_log(2, 'since mb_detect failed - using default of utf-8');}
|
1258 |
+
$charset = 'UTF-8';
|
1259 |
+
}
|
1260 |
+
}
|
1261 |
+
|
1262 |
+
// Since CP1252 is a superset, if we get one of it's subsets, we want it instead.
|
1263 |
+
if ((strtolower($charset) == strtolower('ISO-8859-1')) || (strtolower($charset) == strtolower('Latin1')) || (strtolower($charset) == strtolower('Latin-1')))
|
1264 |
+
{
|
1265 |
+
if (is_object($debug_object)) {$debug_object->debug_log(2, 'replacing ' . $charset . ' with CP1252 as its a superset');}
|
1266 |
+
$charset = 'CP1252';
|
1267 |
+
}
|
1268 |
+
|
1269 |
+
if (is_object($debug_object)) {$debug_object->debug_log(1, 'EXIT - ' . $charset);}
|
1270 |
+
|
1271 |
+
return $this->_charset = $charset;
|
1272 |
+
}
|
1273 |
+
|
1274 |
+
// read tag info
|
1275 |
+
protected function read_tag()
|
1276 |
+
{
|
1277 |
+
if ($this->char!=='<')
|
1278 |
+
{
|
1279 |
+
$this->root->_[HDOM_INFO_END] = $this->cursor;
|
1280 |
+
return false;
|
1281 |
+
}
|
1282 |
+
$begin_tag_pos = $this->pos;
|
1283 |
+
$this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
|
1284 |
+
|
1285 |
+
// end tag
|
1286 |
+
if ($this->char==='/')
|
1287 |
+
{
|
1288 |
+
$this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
|
1289 |
+
// This represents the change in the simple_html_dom trunk from revision 180 to 181.
|
1290 |
+
// $this->skip($this->token_blank_t);
|
1291 |
+
$this->skip($this->token_blank);
|
1292 |
+
$tag = $this->copy_until_char('>');
|
1293 |
+
|
1294 |
+
// skip attributes in end tag
|
1295 |
+
if (($pos = strpos($tag, ' '))!==false)
|
1296 |
+
$tag = substr($tag, 0, $pos);
|
1297 |
+
|
1298 |
+
$parent_lower = strtolower($this->parent->tag);
|
1299 |
+
$tag_lower = strtolower($tag);
|
1300 |
+
|
1301 |
+
if ($parent_lower!==$tag_lower)
|
1302 |
+
{
|
1303 |
+
if (isset($this->optional_closing_tags[$parent_lower]) && isset($this->block_tags[$tag_lower]))
|
1304 |
+
{
|
1305 |
+
$this->parent->_[HDOM_INFO_END] = 0;
|
1306 |
+
$org_parent = $this->parent;
|
1307 |
+
|
1308 |
+
while (($this->parent->parent) && strtolower($this->parent->tag)!==$tag_lower)
|
1309 |
+
$this->parent = $this->parent->parent;
|
1310 |
+
|
1311 |
+
if (strtolower($this->parent->tag)!==$tag_lower) {
|
1312 |
+
$this->parent = $org_parent; // restore origonal parent
|
1313 |
+
if ($this->parent->parent) $this->parent = $this->parent->parent;
|
1314 |
+
$this->parent->_[HDOM_INFO_END] = $this->cursor;
|
1315 |
+
return $this->as_text_node($tag);
|
1316 |
+
}
|
1317 |
+
}
|
1318 |
+
else if (($this->parent->parent) && isset($this->block_tags[$tag_lower]))
|
1319 |
+
{
|
1320 |
+
$this->parent->_[HDOM_INFO_END] = 0;
|
1321 |
+
$org_parent = $this->parent;
|
1322 |
+
|
1323 |
+
while (($this->parent->parent) && strtolower($this->parent->tag)!==$tag_lower)
|
1324 |
+
$this->parent = $this->parent->parent;
|
1325 |
+
|
1326 |
+
if (strtolower($this->parent->tag)!==$tag_lower)
|
1327 |
+
{
|
1328 |
+
$this->parent = $org_parent; // restore origonal parent
|
1329 |
+
$this->parent->_[HDOM_INFO_END] = $this->cursor;
|
1330 |
+
return $this->as_text_node($tag);
|
1331 |
+
}
|
1332 |
+
}
|
1333 |
+
else if (($this->parent->parent) && strtolower($this->parent->parent->tag)===$tag_lower)
|
1334 |
+
{
|
1335 |
+
$this->parent->_[HDOM_INFO_END] = 0;
|
1336 |
+
$this->parent = $this->parent->parent;
|
1337 |
+
}
|
1338 |
+
else
|
1339 |
+
return $this->as_text_node($tag);
|
1340 |
+
}
|
1341 |
+
|
1342 |
+
$this->parent->_[HDOM_INFO_END] = $this->cursor;
|
1343 |
+
if ($this->parent->parent) $this->parent = $this->parent->parent;
|
1344 |
+
|
1345 |
+
$this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
|
1346 |
+
return true;
|
1347 |
+
}
|
1348 |
+
|
1349 |
+
$node = new simple_html_dom_node($this);
|
1350 |
+
$node->_[HDOM_INFO_BEGIN] = $this->cursor;
|
1351 |
+
++$this->cursor;
|
1352 |
+
$tag = $this->copy_until($this->token_slash);
|
1353 |
+
$node->tag_start = $begin_tag_pos;
|
1354 |
+
|
1355 |
+
// doctype, cdata & comments...
|
1356 |
+
if (isset($tag[0]) && $tag[0]==='!') {
|
1357 |
+
$node->_[HDOM_INFO_TEXT] = '<' . $tag . $this->copy_until_char('>');
|
1358 |
+
|
1359 |
+
if (isset($tag[2]) && $tag[1]==='-' && $tag[2]==='-') {
|
1360 |
+
$node->nodetype = HDOM_TYPE_COMMENT;
|
1361 |
+
$node->tag = 'comment';
|
1362 |
+
} else {
|
1363 |
+
$node->nodetype = HDOM_TYPE_UNKNOWN;
|
1364 |
+
$node->tag = 'unknown';
|
1365 |
+
}
|
1366 |
+
if ($this->char==='>') $node->_[HDOM_INFO_TEXT].='>';
|
1367 |
+
$this->link_nodes($node, true);
|
1368 |
+
$this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
|
1369 |
+
return true;
|
1370 |
+
}
|
1371 |
+
|
1372 |
+
// text
|
1373 |
+
if ($pos=strpos($tag, '<')!==false) {
|
1374 |
+
$tag = '<' . substr($tag, 0, -1);
|
1375 |
+
$node->_[HDOM_INFO_TEXT] = $tag;
|
1376 |
+
$this->link_nodes($node, false);
|
1377 |
+
$this->char = $this->doc[--$this->pos]; // prev
|
1378 |
+
return true;
|
1379 |
+
}
|
1380 |
+
|
1381 |
+
if (!preg_match("/^[\w-:]+$/", $tag)) {
|
1382 |
+
$node->_[HDOM_INFO_TEXT] = '<' . $tag . $this->copy_until('<>');
|
1383 |
+
if ($this->char==='<') {
|
1384 |
+
$this->link_nodes($node, false);
|
1385 |
+
return true;
|
1386 |
+
}
|
1387 |
+
|
1388 |
+
if ($this->char==='>') $node->_[HDOM_INFO_TEXT].='>';
|
1389 |
+
$this->link_nodes($node, false);
|
1390 |
+
$this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
|
1391 |
+
return true;
|
1392 |
+
}
|
1393 |
+
|
1394 |
+
// begin tag
|
1395 |
+
$node->nodetype = HDOM_TYPE_ELEMENT;
|
1396 |
+
$tag_lower = strtolower($tag);
|
1397 |
+
$node->tag = ($this->lowercase) ? $tag_lower : $tag;
|
1398 |
+
|
1399 |
+
// handle optional closing tags
|
1400 |
+
if (isset($this->optional_closing_tags[$tag_lower]) )
|
1401 |
+
{
|
1402 |
+
while (isset($this->optional_closing_tags[$tag_lower][strtolower($this->parent->tag)]))
|
1403 |
+
{
|
1404 |
+
$this->parent->_[HDOM_INFO_END] = 0;
|
1405 |
+
$this->parent = $this->parent->parent;
|
1406 |
+
}
|
1407 |
+
$node->parent = $this->parent;
|
1408 |
+
}
|
1409 |
+
|
1410 |
+
$guard = 0; // prevent infinity loop
|
1411 |
+
$space = array($this->copy_skip($this->token_blank), '', '');
|
1412 |
+
|
1413 |
+
// attributes
|
1414 |
+
do
|
1415 |
+
{
|
1416 |
+
if ($this->char!==null && $space[0]==='')
|
1417 |
+
{
|
1418 |
+
break;
|
1419 |
+
}
|
1420 |
+
$name = $this->copy_until($this->token_equal);
|
1421 |
+
if ($guard===$this->pos)
|
1422 |
+
{
|
1423 |
+
$this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
|
1424 |
+
continue;
|
1425 |
+
}
|
1426 |
+
$guard = $this->pos;
|
1427 |
+
|
1428 |
+
// handle endless '<'
|
1429 |
+
if ($this->pos>=$this->size-1 && $this->char!=='>') {
|
1430 |
+
$node->nodetype = HDOM_TYPE_TEXT;
|
1431 |
+
$node->_[HDOM_INFO_END] = 0;
|
1432 |
+
$node->_[HDOM_INFO_TEXT] = '<'.$tag . $space[0] . $name;
|
1433 |
+
$node->tag = 'text';
|
1434 |
+
$this->link_nodes($node, false);
|
1435 |
+
return true;
|
1436 |
+
}
|
1437 |
+
|
1438 |
+
// handle mismatch '<'
|
1439 |
+
if ($this->doc[$this->pos-1]=='<') {
|
1440 |
+
$node->nodetype = HDOM_TYPE_TEXT;
|
1441 |
+
$node->tag = 'text';
|
1442 |
+
$node->attr = array();
|
1443 |
+
$node->_[HDOM_INFO_END] = 0;
|
1444 |
+
$node->_[HDOM_INFO_TEXT] = substr($this->doc, $begin_tag_pos, $this->pos-$begin_tag_pos-1);
|
1445 |
+
$this->pos -= 2;
|
1446 |
+
$this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
|
1447 |
+
$this->link_nodes($node, false);
|
1448 |
+
return true;
|
1449 |
+
}
|
1450 |
+
|
1451 |
+
if ($name!=='/' && $name!=='') {
|
1452 |
+
$space[1] = $this->copy_skip($this->token_blank);
|
1453 |
+
$name = $this->restore_noise($name);
|
1454 |
+
if ($this->lowercase) $name = strtolower($name);
|
1455 |
+
if ($this->char==='=') {
|
1456 |
+
$this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
|
1457 |
+
$this->parse_attr($node, $name, $space);
|
1458 |
+
}
|
1459 |
+
else {
|
1460 |
+
//no value attr: nowrap, checked selected...
|
1461 |
+
$node->_[HDOM_INFO_QUOTE][] = HDOM_QUOTE_NO;
|
1462 |
+
$node->attr[$name] = true;
|
1463 |
+
if ($this->char!='>') $this->char = $this->doc[--$this->pos]; // prev
|
1464 |
+
}
|
1465 |
+
$node->_[HDOM_INFO_SPACE][] = $space;
|
1466 |
+
$space = array($this->copy_skip($this->token_blank), '', '');
|
1467 |
+
}
|
1468 |
+
else
|
1469 |
+
break;
|
1470 |
+
} while ($this->char!=='>' && $this->char!=='/');
|
1471 |
+
|
1472 |
+
$this->link_nodes($node, true);
|
1473 |
+
$node->_[HDOM_INFO_ENDSPACE] = $space[0];
|
1474 |
+
|
1475 |
+
// check self closing
|
1476 |
+
if ($this->copy_until_char_escape('>')==='/')
|
1477 |
+
{
|
1478 |
+
$node->_[HDOM_INFO_ENDSPACE] .= '/';
|
1479 |
+
$node->_[HDOM_INFO_END] = 0;
|
1480 |
+
}
|
1481 |
+
else
|
1482 |
+
{
|
1483 |
+
// reset parent
|
1484 |
+
if (!isset($this->self_closing_tags[strtolower($node->tag)])) $this->parent = $node;
|
1485 |
+
}
|
1486 |
+
$this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
|
1487 |
+
|
1488 |
+
// If it's a BR tag, we need to set it's text to the default text.
|
1489 |
+
// This way when we see it in plaintext, we can generate formatting that the user wants.
|
1490 |
+
// since a br tag never has sub nodes, this works well.
|
1491 |
+
if ($node->tag == "br")
|
1492 |
+
{
|
1493 |
+
$node->_[HDOM_INFO_INNER] = $this->default_br_text;
|
1494 |
+
}
|
1495 |
+
|
1496 |
+
return true;
|
1497 |
+
}
|
1498 |
+
|
1499 |
+
// parse attributes
|
1500 |
+
protected function parse_attr($node, $name, &$space)
|
1501 |
+
{
|
1502 |
+
// Per sourceforge: http://sourceforge.net/tracker/?func=detail&aid=3061408&group_id=218559&atid=1044037
|
1503 |
+
// If the attribute is already defined inside a tag, only pay atetntion to the first one as opposed to the last one.
|
1504 |
+
if (isset($node->attr[$name]))
|
1505 |
+
{
|
1506 |
+
return;
|
1507 |
+
}
|
1508 |
+
|
1509 |
+
$space[2] = $this->copy_skip($this->token_blank);
|
1510 |
+
switch ($this->char) {
|
1511 |
+
case '"':
|
1512 |
+
$node->_[HDOM_INFO_QUOTE][] = HDOM_QUOTE_DOUBLE;
|
1513 |
+
$this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
|
1514 |
+
$node->attr[$name] = $this->restore_noise($this->copy_until_char_escape('"'));
|
1515 |
+
$this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
|
1516 |
+
break;
|
1517 |
+
case '\'':
|
1518 |
+
$node->_[HDOM_INFO_QUOTE][] = HDOM_QUOTE_SINGLE;
|
1519 |
+
$this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
|
1520 |
+
$node->attr[$name] = $this->restore_noise($this->copy_until_char_escape('\''));
|
1521 |
+
$this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
|
1522 |
+
break;
|
1523 |
+
default:
|
1524 |
+
$node->_[HDOM_INFO_QUOTE][] = HDOM_QUOTE_NO;
|
1525 |
+
$node->attr[$name] = $this->restore_noise($this->copy_until($this->token_attr));
|
1526 |
+
}
|
1527 |
+
// PaperG: Attributes should not have \r or \n in them, that counts as html whitespace.
|
1528 |
+
$node->attr[$name] = str_replace("\r", "", $node->attr[$name]);
|
1529 |
+
$node->attr[$name] = str_replace("\n", "", $node->attr[$name]);
|
1530 |
+
// PaperG: If this is a "class" selector, lets get rid of the preceeding and trailing space since some people leave it in the multi class case.
|
1531 |
+
if ($name == "class") {
|
1532 |
+
$node->attr[$name] = trim($node->attr[$name]);
|
1533 |
+
}
|
1534 |
+
}
|
1535 |
+
|
1536 |
+
// link node's parent
|
1537 |
+
protected function link_nodes(&$node, $is_child)
|
1538 |
+
{
|
1539 |
+
$node->parent = $this->parent;
|
1540 |
+
$this->parent->nodes[] = $node;
|
1541 |
+
if ($is_child)
|
1542 |
+
{
|
1543 |
+
$this->parent->children[] = $node;
|
1544 |
+
}
|
1545 |
+
}
|
1546 |
+
|
1547 |
+
// as a text node
|
1548 |
+
protected function as_text_node($tag)
|
1549 |
+
{
|
1550 |
+
$node = new simple_html_dom_node($this);
|
1551 |
+
++$this->cursor;
|
1552 |
+
$node->_[HDOM_INFO_TEXT] = '</' . $tag . '>';
|
1553 |
+
$this->link_nodes($node, false);
|
1554 |
+
$this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
|
1555 |
+
return true;
|
1556 |
+
}
|
1557 |
+
|
1558 |
+
protected function skip($chars)
|
1559 |
+
{
|
1560 |
+
$this->pos += strspn($this->doc, $chars, $this->pos);
|
1561 |
+
$this->char = ($this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
|
1562 |
+
}
|
1563 |
+
|
1564 |
+
protected function copy_skip($chars)
|
1565 |
+
{
|
1566 |
+
$pos = $this->pos;
|
1567 |
+
$len = strspn($this->doc, $chars, $pos);
|
1568 |
+
$this->pos += $len;
|
1569 |
+
$this->char = ($this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
|
1570 |
+
if ($len===0) return '';
|
1571 |
+
return substr($this->doc, $pos, $len);
|
1572 |
+
}
|
1573 |
+
|
1574 |
+
protected function copy_until($chars)
|
1575 |
+
{
|
1576 |
+
$pos = $this->pos;
|
1577 |
+
$len = strcspn($this->doc, $chars, $pos);
|
1578 |
+
$this->pos += $len;
|
1579 |
+
$this->char = ($this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
|
1580 |
+
return substr($this->doc, $pos, $len);
|
1581 |
+
}
|
1582 |
+
|
1583 |
+
protected function copy_until_char($char)
|
1584 |
+
{
|
1585 |
+
if ($this->char===null) return '';
|
1586 |
+
|
1587 |
+
if (($pos = strpos($this->doc, $char, $this->pos))===false) {
|
1588 |
+
$ret = substr($this->doc, $this->pos, $this->size-$this->pos);
|
1589 |
+
$this->char = null;
|
1590 |
+
$this->pos = $this->size;
|
1591 |
+
return $ret;
|
1592 |
+
}
|
1593 |
+
|
1594 |
+
if ($pos===$this->pos) return '';
|
1595 |
+
$pos_old = $this->pos;
|
1596 |
+
$this->char = $this->doc[$pos];
|
1597 |
+
$this->pos = $pos;
|
1598 |
+
return substr($this->doc, $pos_old, $pos-$pos_old);
|
1599 |
+
}
|
1600 |
+
|
1601 |
+
protected function copy_until_char_escape($char)
|
1602 |
+
{
|
1603 |
+
if ($this->char===null) return '';
|
1604 |
+
|
1605 |
+
$start = $this->pos;
|
1606 |
+
while (1)
|
1607 |
+
{
|
1608 |
+
if (($pos = strpos($this->doc, $char, $start))===false)
|
1609 |
+
{
|
1610 |
+
$ret = substr($this->doc, $this->pos, $this->size-$this->pos);
|
1611 |
+
$this->char = null;
|
1612 |
+
$this->pos = $this->size;
|
1613 |
+
return $ret;
|
1614 |
+
}
|
1615 |
+
|
1616 |
+
if ($pos===$this->pos) return '';
|
1617 |
+
|
1618 |
+
if ($this->doc[$pos-1]==='\\') {
|
1619 |
+
$start = $pos+1;
|
1620 |
+
continue;
|
1621 |
+
}
|
1622 |
+
|
1623 |
+
$pos_old = $this->pos;
|
1624 |
+
$this->char = $this->doc[$pos];
|
1625 |
+
$this->pos = $pos;
|
1626 |
+
return substr($this->doc, $pos_old, $pos-$pos_old);
|
1627 |
+
}
|
1628 |
+
}
|
1629 |
+
|
1630 |
+
// remove noise from html content
|
1631 |
+
// save the noise in the $this->noise array.
|
1632 |
+
protected function remove_noise($pattern, $remove_tag=false)
|
1633 |
+
{
|
1634 |
+
global $debug_object;
|
1635 |
+
if (is_object($debug_object)) { $debug_object->debug_log_entry(1); }
|
1636 |
+
|
1637 |
+
$count = preg_match_all($pattern, $this->doc, $matches, PREG_SET_ORDER|PREG_OFFSET_CAPTURE);
|
1638 |
+
|
1639 |
+
for ($i=$count-1; $i>-1; --$i)
|
1640 |
+
{
|
1641 |
+
$key = '___noise___'.sprintf('% 5d', count($this->noise)+1000);
|
1642 |
+
if (is_object($debug_object)) { $debug_object->debug_log(2, 'key is: ' . $key); }
|
1643 |
+
$idx = ($remove_tag) ? 0 : 1;
|
1644 |
+
$this->noise[$key] = $matches[$i][$idx][0];
|
1645 |
+
$this->doc = substr_replace($this->doc, $key, $matches[$i][$idx][1], strlen($matches[$i][$idx][0]));
|
1646 |
+
}
|
1647 |
+
|
1648 |
+
// reset the length of content
|
1649 |
+
|
1650 |
+
$this->size = strlen($this->doc);
|
1651 |
+
if ($this->size>0){
|
1652 |
+
if(is_string($this->doc)){
|
1653 |
+
$this->char = $this->doc[0];
|
1654 |
+
}
|
1655 |
+
}
|
1656 |
+
}
|
1657 |
+
|
1658 |
+
// restore noise to html content
|
1659 |
+
function restore_noise($text)
|
1660 |
+
{
|
1661 |
+
global $debug_object;
|
1662 |
+
if (is_object($debug_object)) { $debug_object->debug_log_entry(1); }
|
1663 |
+
|
1664 |
+
while (($pos=strpos($text, '___noise___'))!==false)
|
1665 |
+
{
|
1666 |
+
// Sometimes there is a broken piece of markup, and we don't GET the pos+11 etc... token which indicates a problem outside of us...
|
1667 |
+
if (strlen($text) > $pos+15)
|
1668 |
+
{
|
1669 |
+
$key = '___noise___'.$text[$pos+11].$text[$pos+12].$text[$pos+13].$text[$pos+14].$text[$pos+15];
|
1670 |
+
if (is_object($debug_object)) { $debug_object->debug_log(2, 'located key of: ' . $key); }
|
1671 |
+
|
1672 |
+
if (isset($this->noise[$key]))
|
1673 |
+
{
|
1674 |
+
$text = substr($text, 0, $pos).$this->noise[$key].substr($text, $pos+16);
|
1675 |
+
}
|
1676 |
+
else
|
1677 |
+
{
|
1678 |
+
// do this to prevent an infinite loop.
|
1679 |
+
$text = substr($text, 0, $pos).'UNDEFINED NOISE FOR KEY: '.$key . substr($text, $pos+16);
|
1680 |
+
}
|
1681 |
+
}
|
1682 |
+
else
|
1683 |
+
{
|
1684 |
+
// There is no valid key being given back to us... We must get rid of the ___noise___ or we will have a problem.
|
1685 |
+
$text = substr($text, 0, $pos).'NO NUMERIC NOISE KEY' . substr($text, $pos+11);
|
1686 |
+
}
|
1687 |
+
}
|
1688 |
+
return $text;
|
1689 |
+
}
|
1690 |
+
|
1691 |
+
// Sometimes we NEED one of the noise elements.
|
1692 |
+
function search_noise($text)
|
1693 |
+
{
|
1694 |
+
global $debug_object;
|
1695 |
+
if (is_object($debug_object)) { $debug_object->debug_log_entry(1); }
|
1696 |
+
|
1697 |
+
foreach($this->noise as $noiseElement)
|
1698 |
+
{
|
1699 |
+
if (strpos($noiseElement, $text)!==false)
|
1700 |
+
{
|
1701 |
+
return $noiseElement;
|
1702 |
+
}
|
1703 |
+
}
|
1704 |
+
}
|
1705 |
+
function __toString()
|
1706 |
+
{
|
1707 |
+
return $this->root->innertext();
|
1708 |
+
}
|
1709 |
+
|
1710 |
+
function __get($name)
|
1711 |
+
{
|
1712 |
+
switch ($name)
|
1713 |
+
{
|
1714 |
+
case 'outer text':
|
1715 |
+
return $this->root->innertext();
|
1716 |
+
case 'inner text':
|
1717 |
+
return $this->root->innertext();
|
1718 |
+
case 'plaintext':
|
1719 |
+
return $this->root->text();
|
1720 |
+
case 'charset':
|
1721 |
+
return $this->_charset;
|
1722 |
+
case 'target_charset':
|
1723 |
+
return $this->_target_charset;
|
1724 |
+
}
|
1725 |
+
}
|
1726 |
+
|
1727 |
+
// camel naming conventions
|
1728 |
+
function childNodes($idx=-1) {return $this->root->childNodes($idx);}
|
1729 |
+
function firstChild() {return $this->root->first_child();}
|
1730 |
+
function lastChild() {return $this->root->last_child();}
|
1731 |
+
function createElement($name, $value=null) {return @str_get_html("<$name>$value</$name>")->first_child();}
|
1732 |
+
function createTextNode($value) {return @end(str_get_html($value)->nodes);}
|
1733 |
+
function getElementById($id) {return $this->find("#$id", 0);}
|
1734 |
+
function getElementsById($id, $idx=null) {return $this->find("#$id", $idx);}
|
1735 |
+
function getElementByTagName($name) {return $this->find($name, 0);}
|
1736 |
+
function getElementsByTagName($name, $idx=-1) {return $this->find($name, $idx);}
|
1737 |
+
function loadFile() {$args = func_get_args();$this->load_file($args);}
|
1738 |
+
}
|
1739 |
+
|
1740 |
+
?>
|
iubenda-cookie-class/test.php
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<html>
|
2 |
+
<head>
|
3 |
+
<!-- Latest compiled and minified CSS -->
|
4 |
+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
|
5 |
+
|
6 |
+
<!-- Optional theme -->
|
7 |
+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
|
8 |
+
<style>
|
9 |
+
ul { margin: 0; padding: 0;}
|
10 |
+
ul li { list-style-type: none; }
|
11 |
+
</style>
|
12 |
+
</head>
|
13 |
+
<body>
|
14 |
+
<div class="container">
|
15 |
+
<div class="row">
|
16 |
+
<div class="col-md-12">
|
17 |
+
<h1>iubenda class test</h1>
|
18 |
+
<form action="" method="POST">
|
19 |
+
<strong>URL WEBSITE</strong><BR>
|
20 |
+
<input type="text" name="url">
|
21 |
+
<input type="submit" class="btn" value="Analyze">
|
22 |
+
</form>
|
23 |
+
</div>
|
24 |
+
|
25 |
+
<?php
|
26 |
+
|
27 |
+
$url = $_POST['url'];
|
28 |
+
if($url){
|
29 |
+
|
30 |
+
|
31 |
+
function print_stuff($array){
|
32 |
+
if(count($array)){
|
33 |
+
echo "<ul>";
|
34 |
+
foreach($array as $r){
|
35 |
+
echo "<li><pre><code>".htmlspecialchars($r)."</code></pre></li>";
|
36 |
+
}
|
37 |
+
echo "</ul>";
|
38 |
+
}else{
|
39 |
+
echo "<p>Nothing</p>";
|
40 |
+
}
|
41 |
+
}
|
42 |
+
|
43 |
+
echo '<div class="col-md-12" style="padding-bottom:150px;"><h2>RESULTS</H2>';
|
44 |
+
include_once 'iubenda.class.php';
|
45 |
+
include_once 'simple_html_dom.php';
|
46 |
+
|
47 |
+
$content = file_get_contents($url);
|
48 |
+
$page = new Page($content);
|
49 |
+
$page->parse();
|
50 |
+
|
51 |
+
$iub_comments_detected = count($page->iub_comments_detected);
|
52 |
+
$scripts_detected = count($page->scripts_detected);
|
53 |
+
$iframe_detected = count($page->iframe_detected);
|
54 |
+
$iframe_converted = count($page->iframe_converted);
|
55 |
+
$script_inline_converted = count($page->scripts_inline_converted);
|
56 |
+
$script_converted = count($page->scripts_converted);
|
57 |
+
|
58 |
+
echo "<p>Iubenda comments detected: $iub_comments_detected<br>Iubenda automatic stuff<br>Iframe detected: $iframe_detected<br>Iframe autoconverted: $iframe_converted<br>Scripts detected: $scripts_detected<br>Inline scripts autoconverted: $script_inline_converted<br>Scripts autoconverted: $script_converted</p>";
|
59 |
+
|
60 |
+
|
61 |
+
|
62 |
+
|
63 |
+
|
64 |
+
echo "<H3>DETAILS</H3>";
|
65 |
+
|
66 |
+
echo "<H4>iubenda comments stuff</h4>";
|
67 |
+
print_stuff($page->iub_comments_detected);
|
68 |
+
|
69 |
+
echo "<H4>Script detected</h4>";
|
70 |
+
print_stuff($page->scripts_detected);
|
71 |
+
echo "<H4>Script converted</h4>";
|
72 |
+
print_stuff($page->scripts_converted);
|
73 |
+
echo "<H4>Script inline converted</h4>";
|
74 |
+
print_stuff($page->scripts_inline_converted);
|
75 |
+
|
76 |
+
echo "<H4>Iframe detected</h4>";
|
77 |
+
print_stuff($page->iframe_detected);
|
78 |
+
echo "<H4>Iframe converted</h4>";
|
79 |
+
print_stuff($page->iframe_converted);
|
80 |
+
|
81 |
+
|
82 |
+
|
83 |
+
echo "</div>";
|
84 |
+
|
85 |
+
|
86 |
+
}
|
87 |
+
?>
|
88 |
+
</div>
|
89 |
+
</div>
|
90 |
+
|
91 |
+
</body>
|
92 |
+
</html>
|
iubenda-cookie-class/usage.php
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
include_once 'simple_html_dom.php';
|
3 |
+
include_once 'iubenda.class.php';
|
4 |
+
|
5 |
+
// Check if the user has already given consent
|
6 |
+
if(!Page::consent_given()){
|
7 |
+
|
8 |
+
$url = 'http://iubenda.com';
|
9 |
+
|
10 |
+
// Here you should pass the content of the page, this is just an example
|
11 |
+
// using file_get_contents(url) to have a real web page
|
12 |
+
$content = file_get_contents($url);
|
13 |
+
|
14 |
+
// Istantiate new Page with content
|
15 |
+
$page = new Page($content);
|
16 |
+
|
17 |
+
// Parse and convert content
|
18 |
+
$page->parse();
|
19 |
+
|
20 |
+
// Print the new page
|
21 |
+
echo $page->get_converted_page();
|
22 |
+
}else{
|
23 |
+
echo 'Consent already given.. print the page without instantiate and parse';
|
24 |
+
}
|
25 |
+
|
26 |
+
?>
|
iubenda_cookie_solution.php
CHANGED
@@ -4,49 +4,21 @@
|
|
4 |
Plugin URI: https://www.iubenda.com
|
5 |
Description: Iubenda Cookie Solution permette di gestire tutti gli aspetti della cookie law su WP.
|
6 |
Author: iubenda
|
7 |
-
Version: 1.9.
|
8 |
Author URI: https://www.iubenda.com
|
9 |
*/
|
10 |
|
11 |
if(!function_exists('file_get_html')){
|
12 |
-
include_once 'simple_html_dom.php';
|
13 |
}
|
|
|
|
|
14 |
|
|
|
15 |
DEFINE('VOICE_MENU', 'Iubenda Cookie Solution');
|
16 |
DEFINE('URL_MENU', str_replace(' ', '_', VOICE_MENU));
|
17 |
DEFINE('IUB_REGEX_PATTERN', '/<!--IUB_COOKIE_POLICY_START-->(.*)<!--IUB_COOKIE_POLICY_END-->/sU');
|
18 |
-
|
19 |
-
|
20 |
-
/***************************************
|
21 |
-
*
|
22 |
-
* Add Iubenda JS script to the header
|
23 |
-
*
|
24 |
-
****************************************/
|
25 |
-
|
26 |
-
function strpos_array($haystack, $needle){
|
27 |
-
if(is_array($needle)){
|
28 |
-
foreach($needle as $need){
|
29 |
-
if(strpos($haystack, $need) !== false){
|
30 |
-
return true;
|
31 |
-
}
|
32 |
-
}
|
33 |
-
}else{
|
34 |
-
if(strpos($haystack, $need) !== false) {
|
35 |
-
return true;
|
36 |
-
}
|
37 |
-
}
|
38 |
-
return false;
|
39 |
-
}
|
40 |
-
|
41 |
-
|
42 |
-
function consentGiven(){
|
43 |
-
foreach($_COOKIE as $key => $value){
|
44 |
-
if(strpos_array($key, array('_iub_cs-s', '_iub_cs'))){
|
45 |
-
return true;
|
46 |
-
}
|
47 |
-
}
|
48 |
-
}
|
49 |
-
|
50 |
|
51 |
|
52 |
function iub_header(){
|
@@ -54,7 +26,7 @@
|
|
54 |
$iub_code = get_option('iub_code');
|
55 |
$str = html_entity_decode(stripslashes($iub_code));
|
56 |
|
57 |
-
if(!
|
58 |
$str.="\n
|
59 |
<script>
|
60 |
(function(){
|
@@ -98,49 +70,6 @@
|
|
98 |
|
99 |
add_action('wp_head', 'iub_header', 99);
|
100 |
|
101 |
-
/***********************************
|
102 |
-
*
|
103 |
-
* Encode all the javascript/html content fetched from this comments:
|
104 |
-
*
|
105 |
-
* <!--IUB_COOKIE_POLICY_START-->
|
106 |
-
* <script>..</script>
|
107 |
-
* <!--IUB_COOKIE_POLICY_END-->
|
108 |
-
*
|
109 |
-
* AND
|
110 |
-
*
|
111 |
-
* [iub-cookie-solution]
|
112 |
-
*
|
113 |
-
* code
|
114 |
-
*
|
115 |
-
* [/iub-cookie-solution]
|
116 |
-
*
|
117 |
-
************************************/
|
118 |
-
|
119 |
-
function create_tags($html){
|
120 |
-
|
121 |
-
$elements = $html->find("*");
|
122 |
-
$js = '';
|
123 |
-
|
124 |
-
foreach($elements as $e){
|
125 |
-
|
126 |
-
switch($e->tag){
|
127 |
-
case 'script':
|
128 |
-
$s = $e->innertext;
|
129 |
-
$js.= '<script type="text/plain" class="_iub_cs_activate">'.$s.'</script>';
|
130 |
-
break;
|
131 |
-
|
132 |
-
default:
|
133 |
-
$js.= '<noscript class="_no_script_iub">';
|
134 |
-
$js.= $e->outertext;
|
135 |
-
$js.= '</noscript>';
|
136 |
-
break;
|
137 |
-
}
|
138 |
-
|
139 |
-
}
|
140 |
-
|
141 |
-
return $js;
|
142 |
-
}
|
143 |
-
|
144 |
|
145 |
function __shutdown(){
|
146 |
$final = '';
|
@@ -162,99 +91,20 @@
|
|
162 |
|
163 |
function __final_output($output){
|
164 |
|
165 |
-
|
166 |
-
'platform.twitter.com/widgets.js',
|
167 |
-
'apis.google.com/js/plusone.js',
|
168 |
-
'apis.google.com/js/platform.js',
|
169 |
-
'connect.facebook.net',
|
170 |
-
'www.youtube.com/iframe_api'
|
171 |
-
);
|
172 |
-
|
173 |
-
$auto_iframe_tags = array(
|
174 |
-
'youtube.com',
|
175 |
-
'platform.twitter.com',
|
176 |
-
'www.facebook.com/plugins/like.php',
|
177 |
-
'apis.google.com'
|
178 |
-
);
|
179 |
-
|
180 |
-
|
181 |
-
if(consentGiven()){
|
182 |
return $output;
|
183 |
}
|
184 |
-
|
185 |
-
/* Replace all the comments with js/html encoded code */
|
186 |
-
preg_match_all(IUB_REGEX_PATTERN, $output, $scripts);
|
187 |
-
if(is_array($scripts[1])){
|
188 |
-
$count = count($scripts[1]);
|
189 |
-
$js_scripts = array();
|
190 |
-
for($j=0; $j<$count; $j++){
|
191 |
-
$html = str_get_html($scripts[1][$j], $lowercase=true, $forceTagsClosed=true, $stripRN=false);
|
192 |
-
$js_scripts[] = create_tags($html);
|
193 |
-
}
|
194 |
-
|
195 |
-
if(is_array($scripts[1]) && is_array($js_scripts)){
|
196 |
-
if(count($scripts[1]) >= 1 && count($js_scripts) >= 1){
|
197 |
-
$output = strtr($output, array_combine($scripts[1], $js_scripts));
|
198 |
-
}
|
199 |
-
}
|
200 |
-
}
|
201 |
-
|
202 |
-
$html = str_get_html($output, $lowercase=true, $forceTagsClosed=true, $stripRN=false);
|
203 |
-
|
204 |
-
if(is_object($html)){
|
205 |
-
/* Auto match script and replace */
|
206 |
-
$scripts = $html->find("script");
|
207 |
-
if(is_array($scripts)){
|
208 |
-
$count = count($scripts);
|
209 |
-
for($j=0; $j<$count; $j++){
|
210 |
-
$s = $scripts[$j];
|
211 |
-
if (strpos_array($s->innertext, $auto_script_tags) !== false) {
|
212 |
-
$class = $s->class;
|
213 |
-
$s->class = $class . ' _iub_cs_activate';
|
214 |
-
$s->type = 'text/plain';
|
215 |
-
}else{
|
216 |
-
$src = $s->src;
|
217 |
-
if (strpos_array($src, $auto_script_tags) !== false) {
|
218 |
-
$class = $s->class;
|
219 |
-
$s->class = $class . ' _iub_cs_activate-inline';
|
220 |
-
$s->type = 'text/plain';
|
221 |
-
}
|
222 |
-
}
|
223 |
-
}
|
224 |
-
}
|
225 |
-
|
226 |
-
/* Auto match iframe and replace */
|
227 |
-
$iframes = $html->find("iframe");
|
228 |
-
if(is_array($iframes)){
|
229 |
-
$count = count($iframes);
|
230 |
-
for($j=0; $j<$count; $j++){
|
231 |
-
$i = $iframes[$j];
|
232 |
-
$src = $i->src;
|
233 |
-
if (strpos_array($src, $auto_iframe_tags) !== false){
|
234 |
-
$new_src = "data:text/html;base64,PGh0bWw+PGJvZHk+U3VwcHJlc3NlZDwvYm9keT48L2h0bWw+";
|
235 |
-
$class = $i->class;
|
236 |
-
$i->suppressedsrc = $src;
|
237 |
-
$i->src = $new_src;
|
238 |
-
$i->class = $class . ' _iub_cs_activate';
|
239 |
-
}
|
240 |
-
}
|
241 |
-
}
|
242 |
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
return $output;
|
247 |
-
}
|
248 |
-
|
249 |
}
|
250 |
|
251 |
-
add_filter('final_output', '__final_output'
|
252 |
|
253 |
|
254 |
function iub_func($atts, $content = "") {
|
255 |
-
|
256 |
-
$html = str_get_html($content, $lowercase=true, $forceTagsClosed=true, $stripRN=false);
|
257 |
-
return create_tags($html);
|
258 |
}
|
259 |
|
260 |
|
@@ -303,9 +153,7 @@
|
|
303 |
<p>
|
304 |
Per informazioni ed istruzioni su questo plugin, visita questa guida:<br>
|
305 |
<a href="https://www.iubenda.com/it/help/posts/810">https://www.iubenda.com/it/help/posts/810</a>
|
306 |
-
|
307 |
-
</p>
|
308 |
-
|
309 |
</div>';
|
310 |
}
|
311 |
|
4 |
Plugin URI: https://www.iubenda.com
|
5 |
Description: Iubenda Cookie Solution permette di gestire tutti gli aspetti della cookie law su WP.
|
6 |
Author: iubenda
|
7 |
+
Version: 1.9.14
|
8 |
Author URI: https://www.iubenda.com
|
9 |
*/
|
10 |
|
11 |
if(!function_exists('file_get_html')){
|
12 |
+
include_once 'iubenda-cookie-class/simple_html_dom.php';
|
13 |
}
|
14 |
+
|
15 |
+
include_once 'iubenda-cookie-class/iubenda.class.php';
|
16 |
|
17 |
+
DEFINE('DEBUG', 0);
|
18 |
DEFINE('VOICE_MENU', 'Iubenda Cookie Solution');
|
19 |
DEFINE('URL_MENU', str_replace(' ', '_', VOICE_MENU));
|
20 |
DEFINE('IUB_REGEX_PATTERN', '/<!--IUB_COOKIE_POLICY_START-->(.*)<!--IUB_COOKIE_POLICY_END-->/sU');
|
21 |
+
DEFINE('IUB_NO_PARSE_GET_PARAM', 'iub_no_parse');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
|
24 |
function iub_header(){
|
26 |
$iub_code = get_option('iub_code');
|
27 |
$str = html_entity_decode(stripslashes($iub_code));
|
28 |
|
29 |
+
if(!Page::consent_given() && !DEBUG || $_GET[IUB_NO_PARSE_GET_PARAM]){
|
30 |
$str.="\n
|
31 |
<script>
|
32 |
(function(){
|
70 |
|
71 |
add_action('wp_head', 'iub_header', 99);
|
72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
74 |
function __shutdown(){
|
75 |
$final = '';
|
91 |
|
92 |
function __final_output($output){
|
93 |
|
94 |
+
if(Page::consent_given() && !DEBUG || $_GET[IUB_NO_PARSE_GET_PARAM]){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
return $output;
|
96 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
|
98 |
+
$page = new Page($output);
|
99 |
+
$page->parse();
|
100 |
+
return $page->get_converted_page();
|
|
|
|
|
|
|
101 |
}
|
102 |
|
103 |
+
add_filter('final_output', '__final_output');
|
104 |
|
105 |
|
106 |
function iub_func($atts, $content = "") {
|
107 |
+
return '<!--IUB_COOKIE_POLICY_START-->'.do_shortcode($content).'<!--IUB_COOKIE_POLICY_END-->';
|
|
|
|
|
108 |
}
|
109 |
|
110 |
|
153 |
<p>
|
154 |
Per informazioni ed istruzioni su questo plugin, visita questa guida:<br>
|
155 |
<a href="https://www.iubenda.com/it/help/posts/810">https://www.iubenda.com/it/help/posts/810</a>
|
156 |
+
</p>
|
|
|
|
|
157 |
</div>';
|
158 |
}
|
159 |
|
readme.txt
CHANGED
@@ -8,7 +8,7 @@ Stable tag: 1.0
|
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
11 |
-
A plugin
|
12 |
|
13 |
== Description ==
|
14 |
|
@@ -28,27 +28,53 @@ Under "Installation/Other Notes" you will find instructions in both English and
|
|
28 |
**NOTE: This plugin is a very early beta and could lead to problems.** We encourage you to actively let us know about the problems here: http://gsfn.us/t/4qpks
|
29 |
|
30 |
- **Installation via WP.org**: search in your WordPress plugin admin panel for "Iubenda Cookie Solution", install it;
|
31 |
-
- Once the plugin is installed and activated, go to the Admin Panel (Settings > Iubenda Cookie Solution) where you will be asked to paste the code into tht field that gets generated from your Iubenda account dashboard when you activate the cookie law kit for your privacy policy. For more information on how to activate the cookie law kit, see this article: https://www.iubenda.com/it/help/posts/680
|
32 |
-
- At this point the plugin will begin to show the banner on which displays your cookie policy (link) to users who visit the site for the first time. No need for other configurations
|
33 |
-
- Furthermore, the plugin automatically recognizes and blocks cookies that get installed via the YouTube video player and social widgets - such as the Facebook Like Box - on your site.
|
34 |
- The other scripts that install cookies for which the automatic block isn't yet available can and should be "wrapped" using these comments:
|
35 |
|
36 |
`<!--IUB_COOKIE_POLICY_START-->
|
37 |
<!--IUB_COOKIE_POLICY_END-->`
|
38 |
|
39 |
- **Installazione automatica**: installa da WordPres.org cercando "Iubenda Cookie Solution";
|
40 |
-
- Una volta installato ed attivato il plugin, accedi al pannello Admin (Impostazioni > Iubenda Cookie Solution) dove ti verrà chiesto di incollare in un campo il codice che iubenda genera quando attivi il kit cookie law sulla tua privacy policy. Per ulteriori informazioni su come attivare il kit cookie law, consulta questo articolo: https://www.iubenda.com/it/help/posts/680
|
41 |
-
- A questo punto il plugin inizierà a mostrare il banner in cui è richiamata la tua cookie policy agli utenti che visitano il sito per la prima volta senza la necessità di altre configurazioni
|
42 |
-
- In più, il plugin riconoscerà e bloccherà in automatico i cookie installati da tutti i video player di YouTube e dai widget sociali – come il Facebook Like Box – presenti sul tuo sito.
|
43 |
- Gli altri script per i quali non è ancora disponibile il blocco automatico – e che installano cookie che richiedono il blocco prima del consenso – vanno “avvolti” utilizzando questi commenti:
|
44 |
|
45 |
`<!--IUB_COOKIE_POLICY_START-->
|
46 |
<!--IUB_COOKIE_POLICY_END-->`
|
47 |
|
|
|
|
|
|
|
|
|
|
|
48 |
== Changelog ==
|
49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
= 1.9.7 =
|
51 |
-
* minor bugfix
|
52 |
|
53 |
= 1.9.6 =
|
54 |
* bugfix: custom banner now allowed
|
@@ -109,12 +135,14 @@ In case of continued browsing, the preferences of your users for the use of cook
|
|
109 |
|
110 |
At the moment the automatic blocking of the YouTube video player and social widgets are done only if these scripts are located after the function wp_head(). The solution is the first version. Test it and contact us to report any errors.
|
111 |
|
112 |
-
|
|
|
|
|
113 |
|
114 |
* The best way you can help us is by providing as much information as possible, including the use of wp_debug https://codex.wordpress.org/Debugging_in_WordPress.
|
115 |
* We will be very happy to receive feedback here: http://gsfn.us/t/4qpks
|
116 |
|
117 |
-
|
118 |
|
119 |
Per esempio in un plugin Facebook dovrai fare come segue:
|
120 |
|
@@ -148,7 +176,7 @@ In caso di proseguimento della navigazione, le preferenze dei tuoi utenti circa
|
|
148 |
|
149 |
Al momento il blocco automatico dei video player di YouTube e dei widget sociali avviene solo se questi script si trovano dopo la funzione wp_head(). La soluzione è alla prima versione. Testatela e contattateci per segnalare eventuali errori.
|
150 |
|
151 |
-
|
152 |
|
153 |
* Il modo migliore per aiutarci è quello di fornire quante più informazioni possibili, compreso l'uso di wp_debug https://codex.wordpress.org/Debugging_in_WordPress.
|
154 |
* Saremo molto contenti di ricevere feedback qui: http://gsfn.us/t/4qpks
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
11 |
+
A plugin that works with the iubenda Cookie Law Solution that shows a cookie banner & allows blocking prior to consent, particularly fit for Italy.
|
12 |
|
13 |
== Description ==
|
14 |
|
28 |
**NOTE: This plugin is a very early beta and could lead to problems.** We encourage you to actively let us know about the problems here: http://gsfn.us/t/4qpks
|
29 |
|
30 |
- **Installation via WP.org**: search in your WordPress plugin admin panel for "Iubenda Cookie Solution", install it;
|
31 |
+
- Once the plugin is installed and activated, go to the Admin Panel (Settings > Iubenda Cookie Solution) where you will be asked to paste the code into tht field that gets generated from your Iubenda account dashboard when you activate the cookie law kit for your privacy policy. For more information on how to activate the cookie law kit, see this article: https://www.iubenda.com/it/help/posts/680;
|
32 |
+
- At this point the plugin will begin to show the banner on which displays your cookie policy (link) to users who visit the site for the first time. No need for other configurations;
|
33 |
+
- Furthermore, the plugin automatically recognizes and blocks cookies that get installed via the YouTube video player and social widgets - such as the Facebook Like Box - on your site. **Important note** the scripts for Facebook, Twitter, G+, and YouTube iframe only get blocked automatically when generated from the server side (therefore processed by PHP via WordPress). Scripts that are added to the page via Javascript after page load cannot be blocked automatically;
|
34 |
- The other scripts that install cookies for which the automatic block isn't yet available can and should be "wrapped" using these comments:
|
35 |
|
36 |
`<!--IUB_COOKIE_POLICY_START-->
|
37 |
<!--IUB_COOKIE_POLICY_END-->`
|
38 |
|
39 |
- **Installazione automatica**: installa da WordPres.org cercando "Iubenda Cookie Solution";
|
40 |
+
- Una volta installato ed attivato il plugin, accedi al pannello Admin (Impostazioni > Iubenda Cookie Solution) dove ti verrà chiesto di incollare in un campo il codice che iubenda genera quando attivi il kit cookie law sulla tua privacy policy. Per ulteriori informazioni su come attivare il kit cookie law, consulta questo articolo: https://www.iubenda.com/it/help/posts/680;
|
41 |
+
- A questo punto il plugin inizierà a mostrare il banner in cui è richiamata la tua cookie policy agli utenti che visitano il sito per la prima volta senza la necessità di altre configurazioni;
|
42 |
+
- In più, il plugin riconoscerà e bloccherà in automatico i cookie installati da tutti i video player di YouTube e dai widget sociali – come il Facebook Like Box – presenti sul tuo sito. **Nota importante**: il nostro plugin wordpress blocca in modo automatico tutti gli script Facebook, Twitter, G+, iframe youtube che sono generati lato server (quindi restituiti via PHP da wordpress). Script che vengono inseriti nella pagina dopo il loading della pagina tramite Javascript non sono e non possono essere bloccati in modo automatico;
|
43 |
- Gli altri script per i quali non è ancora disponibile il blocco automatico – e che installano cookie che richiedono il blocco prima del consenso – vanno “avvolti” utilizzando questi commenti:
|
44 |
|
45 |
`<!--IUB_COOKIE_POLICY_START-->
|
46 |
<!--IUB_COOKIE_POLICY_END-->`
|
47 |
|
48 |
+
== Screenshots ==
|
49 |
+
|
50 |
+
1. This screen shot shows the default banner on top of our test site testkada4.altervista.org/cookie-test/example2.html
|
51 |
+
2. When clicking on the cookie policy link, the user gets a view of the entire cookie policy, where they ultimately can give their consent
|
52 |
+
|
53 |
== Changelog ==
|
54 |
|
55 |
+
= 1.9.14 =
|
56 |
+
* Autoconvert iframe vimeo + facebook likebox
|
57 |
+
|
58 |
+
= 1.9.13 =
|
59 |
+
* Now the plugin use iubenda.class.php + fix bug on it.
|
60 |
+
|
61 |
+
= 1.9.12 =
|
62 |
+
* Add iub__no_parse get parameter to skip parsing page
|
63 |
+
|
64 |
+
= 1.9.11 =
|
65 |
+
* Add iub__no_parse get parameter to skip parsing page
|
66 |
+
|
67 |
+
= 1.9.10 =
|
68 |
+
* Another adsense script blocked, another fix on simple html dom
|
69 |
+
|
70 |
+
= 1.9.9 =
|
71 |
+
* Bugs page 60000 chars
|
72 |
+
|
73 |
+
= 1.9.8 =
|
74 |
+
* Added Google Maps & Google Adsense + better shortcode handling
|
75 |
+
|
76 |
= 1.9.7 =
|
77 |
+
* minor bugfix
|
78 |
|
79 |
= 1.9.6 =
|
80 |
* bugfix: custom banner now allowed
|
135 |
|
136 |
At the moment the automatic blocking of the YouTube video player and social widgets are done only if these scripts are located after the function wp_head(). The solution is the first version. Test it and contact us to report any errors.
|
137 |
|
138 |
+
Header image for this plugin page [graciously provided by this person](http://www.sketchappsources.com/free-source/1012-minimal-lines-device-icons-sketch-freebie-resource.html).
|
139 |
+
|
140 |
+
== Bug reports ==
|
141 |
|
142 |
* The best way you can help us is by providing as much information as possible, including the use of wp_debug https://codex.wordpress.org/Debugging_in_WordPress.
|
143 |
* We will be very happy to receive feedback here: http://gsfn.us/t/4qpks
|
144 |
|
145 |
+
== Istruzioni in italiano ==
|
146 |
|
147 |
Per esempio in un plugin Facebook dovrai fare come segue:
|
148 |
|
176 |
|
177 |
Al momento il blocco automatico dei video player di YouTube e dei widget sociali avviene solo se questi script si trovano dopo la funzione wp_head(). La soluzione è alla prima versione. Testatela e contattateci per segnalare eventuali errori.
|
178 |
|
179 |
+
== Segnalazioni di bug ==
|
180 |
|
181 |
* Il modo migliore per aiutarci è quello di fornire quante più informazioni possibili, compreso l'uso di wp_debug https://codex.wordpress.org/Debugging_in_WordPress.
|
182 |
* Saremo molto contenti di ricevere feedback qui: http://gsfn.us/t/4qpks
|
simple_html_dom.php
CHANGED
@@ -72,7 +72,7 @@ function file_get_html($url, $use_include_path = false, $context=null, $offset =
|
|
72 |
$contents = file_get_contents($url, $use_include_path, $context, $offset);
|
73 |
// Paperg - use our own mechanism for getting the contents as we want to control the timeout.
|
74 |
//$contents = retrieve_url_contents($url);
|
75 |
-
if (empty($contents)
|
76 |
{
|
77 |
return false;
|
78 |
}
|
@@ -85,7 +85,7 @@ function file_get_html($url, $use_include_path = false, $context=null, $offset =
|
|
85 |
function str_get_html($str, $lowercase=true, $forceTagsClosed=true, $stripRN=true)
|
86 |
{
|
87 |
$dom = new simple_html_dom(null, $lowercase, $forceTagsClosed, $stripRN);
|
88 |
-
if (empty($str)
|
89 |
{
|
90 |
$dom->clear();
|
91 |
return false;
|
@@ -1174,7 +1174,7 @@ class simple_html_dom
|
|
1174 |
$this->root->_[HDOM_INFO_BEGIN] = -1;
|
1175 |
$this->root->nodetype = HDOM_TYPE_ROOT;
|
1176 |
$this->parent = $this->root;
|
1177 |
-
if ($this->size>0) $this->char = $this->doc[0];
|
1178 |
}
|
1179 |
|
1180 |
// parse html content
|
72 |
$contents = file_get_contents($url, $use_include_path, $context, $offset);
|
73 |
// Paperg - use our own mechanism for getting the contents as we want to control the timeout.
|
74 |
//$contents = retrieve_url_contents($url);
|
75 |
+
if (empty($contents))
|
76 |
{
|
77 |
return false;
|
78 |
}
|
85 |
function str_get_html($str, $lowercase=true, $forceTagsClosed=true, $stripRN=true)
|
86 |
{
|
87 |
$dom = new simple_html_dom(null, $lowercase, $forceTagsClosed, $stripRN);
|
88 |
+
if (empty($str))
|
89 |
{
|
90 |
$dom->clear();
|
91 |
return false;
|
1174 |
$this->root->_[HDOM_INFO_BEGIN] = -1;
|
1175 |
$this->root->nodetype = HDOM_TYPE_ROOT;
|
1176 |
$this->parent = $this->root;
|
1177 |
+
//if ($this->size>0) $this->char = $this->doc[0];
|
1178 |
}
|
1179 |
|
1180 |
// parse html content
|