Sie sind hier : sebastian1012.bplaced.net/ homepage-neu / Kurze-Scripte-und-Codeschnipsel / index.php

Zurück


Der Quellcode dazu


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
<?php
ini_set
('display_errors''0');
if (
array_search(__FILE__get_included_files()) === 0) { header("HTTP/1.1 403 Unauthorized" ); die('Unauthorized. Direct access is not allowed.'); }
if (!
file_exists(getcwd()."/include/simple_html_dom.php")) { die('simple_html_dom.php was not found. Please re-download version 1.5 at <a href="http://sourceforge.net/projects/simplehtmldom/files/">simplehtmldom.sourceforge.net</a>'); }
libxml_use_internal_errors(true);
class 
getGeneral extends DOMDocument {
    public function 
pingHost($host) {
        if (
preg_match('/^https?:\/\//'$host)) { $host preg_replace('/^https?:\/\//'''$host); }
        
$fsock fsockopen($host80$errno$errstr6);
        
$fsockssl fsockopen($host443$errno$errstr6);
        if (!
$fsock) {
            if (!
$fsockssl) {
                return 
false;
                
$host "www.".$host;
                if (!
$fsock) {
                    if (!
$fsockssl) {
                        return 
false;
                    } else {
                        return 
true;
                    }
                } else {
                    return 
true;
                }
            } else {
                return 
true;
            }
        } else {
                return 
true;
        }
    }
    public function 
getDoctype($sitename) {
        
$this->loadHTMLFile($sitename);
        
$name $this->doctype->publicId;
        
$name preg_replace('~.*//DTD(.*?)//.*~''$1'$name);
        if (
$name) {
            return 
$name;
        } else {
            return 
'HTML';
        }
    }
    public function 
getEncoding($sitename) {
        
$html file_get_html($sitename);
        
$el=$html->find('meta[content]',0);
        
$fullvalue $el->content;
        
preg_match('/charset=(.+)/'$fullvalue$matches);
        
$encoding substr($matches[0], strlen("charset="));
        if (
$encoding) {
            return 
$encoding;
        } else {
            return 
'UTF-8';
        }
    }
    public function 
getFavicon($sitename) {
        
$domain parse_url($sitenamePHP_URL_HOST);
        return 
'<img src="http://www.google.com/s2/favicons?domain='.$domain.'" alt="Favicon"/>';
    }
    public function 
getAlexaRank($sitename) {
        
$xml simplexml_load_file('http://data.alexa.com/data?cli=10&dat=snbamz&url='.$sitename);
        
$rank=isset($xml->SD[1]->POPULARITY)?$xml->SD[1]->POPULARITY->attributes()->TEXT:0;
        
$web=(string)$xml->SD[0]->attributes()->HOST;
        return 
$rank;
    }
    public function 
getPageSize($sitename) {
        static 
$regex '/^Content-Length: *+\K\d++$/im';
        if (!
$fp = @fopen($sitename'rb')) {
            return 
false;
        }
        if (isset(
$http_response_header) && preg_match($regeximplode("\n"$http_response_header), $matches)) {
            return (int)
$matches[0];
        }
        
$final strlen(stream_get_contents($fp));
        return 
substr(($final/1024), 07);
    }
    public function 
checkGoogleAnalytics($sitename) {
        
$file file_get_contents($sitename);
        
$ua_regex "/UA-[0-9]{5,}-[0-9]{1,}/";
           
$result preg_match_all($ua_regex$file$match);
           if (!
$result) {
               return 
'Not Found.';
           }
           
$getua array_values(array_filter(array_slice($match,0)));
           
$getuafinal implode(", "$getua[0]);
           if (
$getuafinal) {
               return 
'Found. UID: '.$getuafinal;
           }
    }
    public function 
getGooglePR($sitename) {
        
$query "http://toolbarqueries.google.com/tbr?client=navclient-auto&ch=" $this->CheckHash($this->HashURL($sitename)) . "&features=Rank&q=info:" $sitename "&num=100&filter=0";
        
$data file_get_contents($query);
        
$pos strpos($data"Rank_");
            if (
$pos === false) {
                return 
'0';
            } else {
                
$pagerank substr($data$pos 9);
                return 
$pagerank;
            }
        }
    public function 
getPageTitle($sitename) {
    
$str file_get_contents($sitename);
        if(
strlen($str)>0){
            
preg_match("/\<title\>(.*)\<\/title\>/",$str,$title);
            return 
$title[1];
        }
    }
    public function 
getOther($sitename$tag) {
        
$tags get_meta_tags($sitename);
        if (
$tags[$tag]) {
            return 
$tags[$tag];
        } else {
            return 
'None';
        }
    }
    private function 
StrToNum($Str$Check$Magic) {
        
$Int32Unit 4294967296;
        
$length strlen($Str);
            for (
$i 0$i $length$i++) {
                
$Check*= $Magic;
                if (
$Check >= $Int32Unit) {
                    
$Check = ($Check $Int32Unit * (int)($Check $Int32Unit));
                    
$Check = ($Check < - 2147483648) ? ($Check $Int32Unit) : $Check;
                }
                
$Check+= ord($Str{$i});
            }
        return 
$Check;
    }
    private function 
HashURL($String) {
            
$Check1 $this->StrToNum($String0x15050x21);
            
$Check2 $this->StrToNum($String00x1003F);
            
$Check1 >>= 2;
            
$Check1 = (($Check1 >> 4) & 0x3FFFFC0) | ($Check1 0x3F);
            
$Check1 = (($Check1 >> 4) & 0x3FFC00) | ($Check1 0x3FF);
            
$Check1 = (($Check1 >> 4) & 0x3C000) | ($Check1 0x3FFF);
            
$T1 = (((($Check1 0x3C0) << 4) | ($Check1 0x3C)) << 2) | ($Check2 0xF0F);
            
$T2 = (((($Check1 0xFFFFC000) << 4) | ($Check1 0x3C00)) << 0xA) | ($Check2 0xF0F0000);
            return (
$T1 $T2);
    }
    private function 
CheckHash($Hashnum) {
            
$CheckByte 0;
            
$Flag 0;
            
$HashStr sprintf('%u'$Hashnum);
            
$length strlen($HashStr);
            for (
$i $length 1$i >= 0$i--) {
                
$Re $HashStr{$i};
                if (
=== ($Flag 2)) {
                    
$Re+= $Re;
                    
$Re = (int)($Re 10) + ($Re 10);
                }
                
$CheckByte+= $Re;
                
$Flag++;
            }
            
$CheckByte%= 10;
            if (
!== $CheckByte) {
                
$CheckByte 10 $CheckByte;
                if (
=== ($Flag 2)) {
                    if (
=== ($CheckByte 2)) {
                        
$CheckByte+= 9;
                    }
                    
$CheckByte >>= 1;
                }
            }
        return 
'7' $CheckByte $HashStr;
    }
    public function 
checkRobots($url) {
        
$exists $this->remoteFileExists($url."robots.txt");
        if (
$exists) {
               return 
"Exists";    
        } else {
            return 
"Does not exist";
        }
    }
    private function 
remoteFileExists($url) {
        
$curl curl_init($url);
           
curl_setopt($curlCURLOPT_NOBODYtrue);
        
$result curl_exec($curl);
        
$ret false;
        if (
$result !== false) {
            
$statusCode curl_getinfo($curlCURLINFO_HTTP_CODE);  
            if (
$statusCode == 200) {
                    
$ret true;   
            }
        }
        
curl_close($curl);
        return 
$ret;
    }
    public function 
calculateSEO($url) {
        
$count '0';
        if (
$this->getPageTitle($url)) {$count $count 5;}
        if (
$this->getOther($url'keywords')) {$count $count 5;}
        if (
$this->getOther($url'author')) {$count $count 5;}
        if (
$this->getOther($url'description')) {$count $count 5;}
        if (
$this->getEncoding($url)) {$count $count 5;}
        if (
$this->getFavicon($url)) {$count $count 5;}
        if (
$this->getAlexaRank($url)) {$count $count 10;}
        if (
$this->checkRobots($url)) {$count $count 10;}
        if (
$this->getGooglePR($url) >= 2) {$count $count 20;} elseif ($this->getGooglePR($url) >= 5) {$count $count 30;} elseif ($this->getGooglePR($url) >= 7) {$count $count 40;}
        if (
$this->checkGoogleAnalytics($url) == "Not Found.") {} else {$count $count 10;}
        return 
$count;
    }
}
class 
getResources extends DOMDocument {
    public function 
getCSS($sitename) {
            
$file file_get_contents($sitename);
            
$this->loadHTML($file);
            
$domcss $this->getElementsByTagName('link');
            
$getData '';
            foreach(
$domcss as $links) {
                if( 
strtolower($links->getAttribute('rel')) == "stylesheet" && $links ) {
                       
$getData .= "<a href='".$sitename.$links->getAttribute('href')."'>".$sitename.$links->getAttribute('href')."</a><br />";
                }
            }
            return 
$getData;
    }
    public function 
getCSSCount($sitename) {
            
$count '0';
            
$file file_get_contents($sitename);
            
$this->loadHTML($file);
            
$domcss $this->getElementsByTagName('link');
            foreach(
$domcss as $links) {
                if( 
strtolower($links->getAttribute('rel')) == "stylesheet" ) {
                       
$count++;
                }
            }
            return 
$count;
    }
    public function 
getJS($sitename) {
            
$file file_get_contents($sitename);
            
$this->loadHTML($file);
            
$domcss $this->getElementsByTagName('link');
            
$domcss2 $this->getElementsByTagName('script');
            
$getData '';
            foreach(
$domcss as $links) {
                if(
strtolower($links->getAttribute('rel')) == "javascript" && $links) {
                       
$getData .= $links->getAttribute('href') ."<br />";
                }
            } foreach(
$domcss2 as $links) {
                if (
$links->getAttribute('src') && $links) {
                       
$getData .= "<a href='".$sitename.$links->getAttribute('src')."'>".$sitename.$links->getAttribute('src')."</a><br />";
                   }
            }
            return 
$getData;
    }
    public function 
getJSCount($sitename) {
            
$count '0';
            
$file file_get_contents($sitename);
            
$this->loadHTML($file);
            
$domcss $this->getElementsByTagName('link');
            
$domcss2 $this->getElementsByTagName('script');
            foreach(
$domcss as $links) {
                if( 
strtolower($links->getAttribute('rel')) == "javascript" ) {
                       
$count++;
                }
            } foreach(
$domcss2 as $links) {
                   
$count++;
            }
            return 
$count;
    }
    public function 
getImages($sitename) {
        
$html file_get_contents($sitename);
        
$this->loadHTML($html);
        
$images $this->getElementsByTagName('img');
        
$getData '';
        foreach (
$images as $image) {
              
$getData .= "<a href='".$sitename.$image->getAttribute('src')."'>".$sitename.$image->getAttribute('src')."</a><br />";
        }
        return 
$getData;
    }
    public function 
getImageCount($sitename) {
        
$count '0';
        
$html file_get_contents($sitename);
        
$this->loadHTML($html);
        
$images $this->getElementsByTagName('img');
        foreach (
$images as $image) {
              
$count++;
        }
        return 
$count;
    }
}
class 
getMeta extends DOMDocument {
    public function 
getLinks($url){
        
$url htmlentities(strip_tags($url));
        
$ExplodeUrlInArray explode('/',$url);
        
$DomainName $ExplodeUrlInArray[2];
        
$file = @file_get_contents($url);
        
$h1count preg_match_all('/(href=["|\'])(.*?)(["|\'])/i',$file,$patterns);
        
$linksInArray $patterns[2];
        
$CountOfLinks count($linksInArray);
        
$InternalLinkCount 0;
        
$ExternalLinkCount 0;
        for(
$Counter=0;$Counter<$CountOfLinks;$Counter++){
             if(
$linksInArray[$Counter] == "" || $linksInArray[$Counter] == "#")
              continue;
            
preg_match('/javascript:/'$linksInArray[$Counter],$CheckJavascriptLink);
        if(
$CheckJavascriptLink != NULL)
            continue;
            
$Link $linksInArray[$Counter];
            
preg_match('/\?/'$linksInArray[$Counter],$CheckForArgumentsInUrl);
        if(
$CheckForArgumentsInUrl != NULL) {
            
$ExplodeLink explode('?',$linksInArray[$Counter]);
            
$Link $ExplodeLink[0];
        }
        
preg_match('/'.$DomainName.'/',$Link,$Check);
        if(
$Check == NULL) {
            
preg_match('/http:\/\//',$Link,$ExternalLinkCheck);
            if(
$ExternalLinkCheck == NULL) {
                
$InternalDomainsInArray[$InternalLinkCount] = $Link;
                
$InternalLinkCount++;
            } else {
            
$ExternalDomainsInArray[$ExternalLinkCount] = $Link;
            
$ExternalLinkCount++;
            }
        }
        else {
        
$InternalDomainsInArray[$InternalLinkCount] = $Link;
        
$InternalLinkCount++;
        }
        }
        
$LinksResultsInArray = array(
        
'ExternalLinks'=>$ExternalDomainsInArray,
        
'InternalLinks'=>$InternalDomainsInArray
        
);
        return 
$LinksResultsInArray;
    }
    public function 
getPageText($sitename) {
        
$url file_get_contents($sitename);
        
$text mb_convert_case($urlMB_CASE_LOWER"UTF-8");
        
$text str_replace("\n\r"," ",$text);
        
$text str_replace("\n"," ",$text);
        
$text str_replace("\r"," ",$text);
        
$text str_replace("/>"," />",$text);
        
        
$text str_replace("&nbsp;"," ",$text);
        
        
$text preg_replace("/<( )*script([^>])*>/i""<script>"$text);
        
$text preg_replace("/<script[^>]*>[\s\S]*?<\/script>/i"""$text);
        
$text preg_replace("/<style[^>]*>[\s\S]*?<\/style>/i"""$text);
        
$text preg_replace("/<iframe[^>]*>[\s\S]*?<\/iframe>/i"""$text);
        
$text preg_replace("/<head[^>]*>[\s\S]*?<\/head>/i"""$text);
        
$text preg_replace("/<meta([^>])*\/>/i"""$text);
        
$text preg_replace("/<script[^>]*>[\s\S]*?<\/script>/i"""$text);
        
$text preg_replace("/<td[^>]*>/"" "$text);
        
$text preg_replace("/<p[^>]*>/"" "$text);
        
$text preg_replace("/<b[^>]*>/"" "$text);
        
$text preg_replace("/<br[^>]*>/"" "$text);
        
$text preg_replace("/<[^>]*>/"""$text);
        
        while(
strpos($text,"\t")!==false$text str_replace("\t"" "$text);
        while(
strpos($text,'  ')!==false$text str_replace("  "" "$text);
        
        
$text trim($text);
        
$text html_entity_decode($textENT_QUOTES,"UTF-8");
        
$trans_tbl get_html_translation_table(HTML_ENTITIES);
        
$trans_tbl array_flip($trans_tbl);
        
        return 
trim(strtr(trim($text), $trans_tbl));
    }
    public function 
getWordCount($sitetext$nofwords) {
        
$text $this->prepare($sitetext);
        while(
strpos($text,'  ')!==false$text preg_replace("/  /"" "$text);
        
$string $text;
        
$text=explode(" ",trim($text));
        
$keywords=array();
        
$text=array_unique($text);
        
$nr_words=$this->prepare2($string);
        foreach(
$text as $t=>$k)
        {
            
$nr_finds=$this->prepare3($k,$string);    
            if(
$nr_finds>=$this->minoc && strlen($k)>=$this->minlength) {
                if (
$keywords[$k]=$nr_finds $nofwords) {
                    
$percent = (($nr_finds $this->getTotalWords($sitetext)) * 100);
                    
$keywords[$k]=array($nr_finds,$percent);
                } else {
                    
$keywords[$k] = array();
                }
            }
        }
        
arsort($keywords);
        return 
$keywords;
    }
    private function 
prepare($text) {
        
$badchar = array("ā","Ā","ī","Ī","ü","ū","Ū","Ü","ṃ","Ṃ","ḥ","Ḥ","ṇ","Ṇ","ṣ","Ṣ","ś","Ś","ṛ","Ṛ","ṝ","Ṝ","ḷ","Ḷ","ṭ","Ṭ","ṭh","Ṭh","ḍ","Ḍ","ḍh","Ḍh","ṅ","Ṅ","ñ","Ñ","ḹ","Ḹ","ľ","š","č","ť","ž","ý","á","í","é","ú","ä","ô","ó","ö","ň","ů","ř","ě","ď","Ř","Ť","Š","Ď","Ě","Č","Ž","Ň","Ľ","Á","É","Í","Ó","Ú","ĺ","Ĺ","Ä","Ö","Ü","ß","ć","đ","ő","ű","ñ","à","â","ç","è","ê","ë","î","ï","û","ù","ü","ÿ","ñ""œ""æ","'");
        
$newchar = array("a","A","i","I","u","u","U","U","m","M","h","H","n","N","s","S","s","S","r","R","r","R","l","L","t","T","th","Th","d","D","dh","Dh","n","N","n","N","l","L","l","s","c","t","z","y","a","i","e","u","a","o","o","o","n","u","r","e","d","R","T","S","D","E","C","Z","N","L","A","E","I","O","U","l","L","A","O","U","B","c","d","o","u","n","a","a","c","e","e","e","i","i","u","u","u","y","n","oe","ae","-");
        
$value str_replace($badchar$newchar$value); 
        
$value preg_replace("@[^A-Za-z0-9\-_\s]+@i"""$value);
        return 
$text;
    }
    private function 
prepare2($str) {
        
$tmp=0;
        
$tok strtok ($str," ");
        while (
$tok) {
        
$tmp++;
        
$tok strtok (" ");
        }
        return 
$tmp;
    }
    
    private function 
prepare3($key,$string) {
        
$q=0;
        
$nr=0;
        
$key=strtolower($key);
        
$string=strtolower($string);
        while(
$q==0)
        {
            
$pos = @strpos($string,$key);
            if (
$pos===false$q=1;
            else 
            {
                
$string substr ($string,$pos+strlen($key));
                
$nr++;
            }
        }
        return 
$nr;
    }
    public function 
getTotalWords($text) {
        
$text $this->prepare($text); 
        
preg_replace("/[^a-zA-Z0-9äôáéíóúýĺďťňľščžťřěÁÉÍÓÚÝĹĎŤŇĽŠČŽŤŘĚ ]/"""$text);
        while(
strpos($text,'  ')!==false$text preg_replace("/\s\s/"" "$text);
        
$text=explode(" ",trim($text));
        return 
count($text);
    }
}
class 
getHeadings extends DOMDocument {
    public function 
getHeading($sitename$htype) {
        
$html file_get_contents($sitename);
        
$this->loadHTML($html);
        
$h $this->getElementsByTagName($htype);
        
$getData '';
        foreach (
$h as $hh) {
              
$getData .= $hh->nodeValue.'<br/>';
        }
        return 
$getData;
    }
    public function 
getHeadingCount($sitename$htype) {
        
$count '0';
        
$html file_get_contents($sitename);
        
$this->loadHTML($html);
        
$h $this->getElementsByTagName($htype);
        foreach (
$h as $hh) {
              
$count++;
        }
        return 
$count;
    }
}
?>