=3) return isset($x[2][0]) ? $x[2][0] : ""; return ""; } private function makeabsolute($url,$link) { $p = parse_url($url); if (strpos( $link,"http://")===0 ) return $link; if($p['scheme']."://".$p['host']==$url && $link[0]!="/" && $link!=$url) return $p['scheme']."://".$p['host']."/".$link; if (strpos( $link, "/")===0) return "http://".$p['host'].$link; return str_replace(substr(strrchr($url, "/"), 1),"",$url).$link; } function on_curl_header($ch, $header) { // to handle file size check and prevent downloading too much $trimmed = rtrim($header); if (preg_match('/^Content-Length: (\d+)$/i', $trimmed, $matches)) { $file_size = (float)$matches[1]; if ($file_size > $this->max_file_size) { // stop if bigger return -1; } } return strlen($header); } function on_curl_write($ch, $data) { // to handle file size check and prevent downloading too much $bytes = strlen($data); $this->file_size += $bytes; $this->file_downloaded .= $data; if ($this->file_size > $this->max_file_size) { // stop if bigger return -1; } return $bytes; } private function getRemoteFileSize($url) { if (substr($url,0,4)=='http') { $x = array_change_key_case(get_headers($url, 1),CASE_LOWER); if ( strcasecmp($x[0], 'HTTP/1.1 200 OK') != 0 ) { $x = $x['content-length'][1]; } else { $x = $x['content-length']; } } else { $x = @filesize($url); } return $x; } public function doSpelling($q) { // (thanks to google) // grab google page with search $web_page = file_get_contents( "http://www.google.it/search?q=" . urlencode($q) ); // put anchors tag in an array preg_match_all('#]*)?>(.*)#Us', $web_page, $a_array); for($j=0;$jdayadd(-1,$d,"Y-m-d") ); $web_page = file_get_contents( "http://uif.bancaditalia.it/UICFEWebroot/QueryOneDateAllCur?lang=en&rate=0&initDay=".$dar[2]."&initMonth=".$dar[1]."&initYear=".$dar[0]."&refCur=euro&R1=csv"); // parse csv results $lines = explode("\n",$web_page); for($j=0;$j$this->dayadd(3,date("Y-m-d"),"Y-m-d"))return ""; // grab google page with meteo query $web_page = file_get_contents( "http://www.google.it/search?q=meteo+" . urlencode($q) ); //parse to find data preg_match_all('#
(.*)#Us', $web_page, $m); if (count($m)>0) { $p = array(); preg_match_all('#]*)?>#Us', $m[0][0], $img); for ($i=0;$idayadd($i,date("Y-m-d"),"Y-m-d"); $p[$i]["title"] = $this->attr($tag,"title"); $p[$i]["img"] = $this->attr($tag,"src"); } preg_match_all('#(.*)#Uis', $m[0][0], $nobr); for ($i=0;$igetHttpResponseCode($url) == 200); } public function doGeoIp($ip="") { //(thanks to geoiptool) // ----------------------------------------------------------------------------------- // better use this free api: http://ipinfodb.com/ip_query.php?ip=62.149.150.92 // that returns clean xml code. if (!$ip) $ip = $this->getIP(); $ar = array(); $web_page = file_get_contents( "http://www.geoiptool.com/en/?IP=".$ip ); preg_match_all('#]*)tbl_style([^>]*)?>(.*)#Us', $web_page, $t_array); for($j=0;$j]*)?>(.*)#Us', $table, $tr_array); for($i=0;$i 0) { # -------------------------------- # Check if mailers accept mail # -------------------------------- for($n=0; $n < $total; $n++) { # -------------------------------- # Check if socket can be opened # -------------------------------- if($debug) { $output .= "Checking server $mailers[$n]...\n";} $connect_timeout = 2; $errno = 0; $errstr = 0; # -------------------------------- # controllo probe address # -------------------------------- if (preg_match('/^([a-zA-Z0-9\._\+-]+)\@((\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,7}|[0-9]{1,3})(\]?))$/', $probe_address,$fakematches)) { $probe_domain = str_replace("@","",strstr($probe_address, '@')); # -------------------------------- # Try to open up socket # -------------------------------- if($sock = @fsockopen($mailers[$n], 25, $errno , $errstr, $connect_timeout)) { $response = fgets($sock); if($debug) {$output .= "Opening up socket to $mailers[$n]... Success!\n";} stream_set_timeout($sock, 5); $meta = stream_get_meta_data($sock); if($debug) { $output .= "$mailers[$n] replied: $response\n";} # -------------------------------- # Be sure to set this correctly! # -------------------------------- $cmds = array( "HELO $probe_domain", "MAIL FROM: <$probe_address>", "RCPT TO: <$email>", "QUIT", ); # -------------------------------- # Hard error on connect -> break out # -------------------------------- if(!$meta['timed_out'] && !preg_match('/^2\d\d[ -]/', $response)) { $codice = trim(substr(trim($response),0,3)); if ($codice=="421") { //421 #4.4.5 Too many connections to this host. $error = $response; break; } else { if($response=="" || $codice=="") { //c'è stato un errore ma la situazione è poco chiara $codice = "0"; } $error = "Error: $mailers[$n] said: $response\n"; break; } break; } foreach($cmds as $cmd) { $before = microtime(true); fputs($sock, "$cmd\r\n"); $response = fgets($sock, 4096); $t = 1000*(microtime(true)-$before); if($debug) {$output .= "$cmd\n$response" . "(" . sprintf('%.2f', $t) . " ms)\n";} if(!$meta['timed_out'] && preg_match('/^5\d\d[ -]/', $response)) { $codice = trim(substr(trim($response),0,3)); if ($codice<>"552") { $error = "Unverified address: $mailers[$n] said: $response"; break 2; } else { $error = $response; break 2; } # -------------------------------- // il 554 e il 552 sono quota // 554 Recipient address rejected: mailbox overquota // 552 RCPT TO: Mailbox disk quota exceeded # -------------------------------- } } fclose($sock); if($debug) { $output .= "Succesful communication with $mailers[$n], no hard errors, assuming OK\n";} break; } elseif($n == $total-1) { $error = "None of the mailservers listed for $domain could be contacted"; $codice = "0"; } } else { $error = "Il probe_address non è una mail valida."; } } } elseif($total <= 0) { $error = "No usable DNS records found for domain '$domain'"; } } } else { $error = 'Address syntax not correct'; } if($debug) { print nl2br(htmlentities($output)); } if(!isset($codice)) {$codice="n.a.";} if(isset($error)) return array($error,$codice); else return true; } public function getUrlInfo($url,$maximages=5,$maxkbimg=10) { if (!function_exists("curl_init")) die("getUrlInfo needs CURL module, please install CURL on your php."); // this bot retrieves info about a url: // keywords, title, description,favicon and images // $url = $this->makeabsolute($url, $this->doShortURLDecode($url)); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FAILONERROR, 1); // Fail on errors curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable curl_setopt($ch, CURLOPT_PORT, 80); //Set the port number curl_setopt($ch, CURLOPT_TIMEOUT, 15); // times out after 15s if($maximages==0) { // if you don't want images from html // use only first 5 kb to reduce band used and time $this->max_file_size = 5000; curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, 'on_curl_header')); curl_setopt($ch, CURLOPT_WRITEFUNCTION, array($this, 'on_curl_write')); } $web_page = curl_exec($ch); if(strlen($web_page) <= 1 && $maximages==0) { $web_page = $this->file_downloaded; } //$web_page = file_get_contents($url); $data['keywords']=""; $data['description']=""; $data['title']=""; $data['favicon']=""; $data['images']=array(); $data['thumbsite']="http://open.thumbshots.org/image.pxf?url=".urlencode($url); //search title preg_match_all('#]*)?>(.*)#Uis', $web_page, $title_array); $data['title'] = $title_array[2][0]; //search keywords and description preg_match_all('#]*)(.*)>#Uis', $web_page, $meta_array); //print_r($meta_array); for($i=0;$iattr($meta_array[0][$i],"name"))=='description') $data['description'] = $this->attr($meta_array[0][$i],"content"); if (strtolower($this->attr($meta_array[0][$i],"name"))=='keywords') $data['keywords'] = $this->attr($meta_array[0][$i],"content"); } //search favicon preg_match_all('#]*)(.*)>#Uis', $web_page, $link_array); for($i=0;$iattr($link_array[0][$i],"rel"))=='shortcut icon') $data['favicon'] = $this->makeabsolute($url,$this->attr($link_array[0][$i],"href")); } // search images big enough preg_match_all('#]*)(.*)/?>#Uis', $web_page, $imgs_array); $imgs = array(); for($i=0;$iattr($imgs_array[0][$i],"src")) { $src = $this->makeabsolute($url,$src); if(!in_array($src,$imgs) && $this->getRemoteFileSize($src)>$maxkbimg*1000) array_push($imgs,$src); } if (count($imgs)>$maximages-1) break; } $data['images']=$imgs; return $data; } public function getUrlInfoFast($url,$maxbytes=4096) { if (!function_exists("curl_init")) die("getUrlInfo needs CURL module, please install CURL on your php."); $url = $this->makeabsolute($url, $this->doShortURLDecode($url)); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FAILONERROR, 0); // Fail on errors curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable curl_setopt($ch, CURLOPT_TIMEOUT, 15); // times out after 15s $this->max_file_size = $maxbytes; //curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, 'on_curl_header')); curl_setopt($ch, CURLOPT_WRITEFUNCTION, array($this, 'on_curl_write')); $web_page = curl_exec($ch); if(strlen($web_page) <= 1) $web_page = $this->file_downloaded; $data['d']=""; $data['t']=""; $data['f']=""; $data['e']=""; // per mettere automaticamente embed di player video youtube e mp3 $data['g']=""; // trigger per visualizzare embed //search title preg_match_all('#]*)?>(.*)#Uis', $web_page, $title_array); $data['t'] = isset($title_array[2][0]) ? trim(preg_replace('/ +/', ' ', $title_array[2][0])) : "senza titolo"; //search keywords and description preg_match_all('#]*)(.*)>#Uis', $web_page, $meta_array); //print_r($meta_array); for($i=0;$iattr($meta_array[0][$i],"name"))=='description') $data['d'] = $this->attr($meta_array[0][$i],"content"); //search favicon preg_match_all('#]*)(.*)>#Uis', $web_page, $link_array); for($i=0;$iattr($link_array[0][$i],"rel"))=='shortcut icon') $data['f'] = $this->makeabsolute($url,$this->attr($link_array[0][$i],"href")); } $trigger = ""; $embed = ""; //http://www.youtube.com/v/Md1E_Rg4MGQ&hl=en&fs=1& //http://www.youtube.com/watch?v=Md1E_Rg4MGQ&feature=aso preg_match_all('/^http:\/\/www.youtube.com\/(v\/|watch\?v=)([^&]*)(.*)$/', $url, $yarr); if(isset($yarr[2][0])) { $trigger = ""; $embed = $this->resizeEmbed( '', 400); } //http://vimeo.com/17116744 preg_match_all('/^http:\/\/vimeo.com\/([0-9]*)$/', $url, $varr); if(isset($varr[1][0])) { $trigger = ""; $embed = $this->resizeEmbed( '' , 400); } $data["e"] = $embed; $data["g"] = $trigger; return $data; } // // copy remote file to server private function copyFile($url,$filename){ $file = fopen ($url, "rb"); if (!$file) return false; else { $fc = fopen($filename, "wb"); while (!feof ($file)) { $line = fread ($file, 1028); fwrite($fc,$line); } fclose($fc); return true; } } // // save a url to a local pdf using pdfmyurl.com service public function url2pdf($url,$pdffilename) { return $this->copyFile("http://pdfmyurl.com?url=".urlencode( str_replace("http://","",$url) ), $pdffilename); } // // save a url to a local jpg thumb using open.thumbshots.com service public function url2thumb($url,$thumbfilename) { return $this->copyFile("http://open.thumbshots.org/image.pxf?url=".urlencode( $url ), $thumbfilename); } // // return text from a url // thanks to php.net public function webpage2txt($url) { if (!function_exists("curl_init")) die("webpage2txt needs CURL module, please install CURL on your php."); $user_agent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; it; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8"; $ch = curl_init(); // initialize curl handle curl_setopt($ch, CURLOPT_URL, $url); // set url to post to curl_setopt($ch, CURLOPT_FAILONERROR, 1); // Fail on errors curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable curl_setopt($ch, CURLOPT_PORT, 80); //Set the port number curl_setopt($ch, CURLOPT_TIMEOUT, 15); // times out after 15s curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); $document = curl_exec($ch); $search = array('@]*?>.*?@si', // Strip out javascript '@]*?>.*?@siU', // Strip style tags properly '@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags '@@', // Strip multi-line comments including CDATA '/\s{2,}/', ); $text = preg_replace($search, " ", html_entity_decode($document)); $pat[0] = "/^\s+/"; $pat[2] = "/\s+\$/"; $rep[0] = ""; $rep[2] = " "; $text = preg_replace($pat, $rep, trim($text)); return $text; } public function twitterSetStatus($user,$pwd,$status) { if (!function_exists("curl_init")) die("twitterSetStatus needs CURL module, please install CURL on your php."); $ch = curl_init(); // ------------------------------------------------------- // get login form and parse it curl_setopt($ch, CURLOPT_URL, "https://mobile.twitter.com/session/new"); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_FAILONERROR, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt"); curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt"); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3 "); $page = curl_exec($ch); $page = stristr($page, "