. * @author Gündüz Can YILMAZ * @copyright 2009-2010 * @version 1.1.0 * @access public * @site http://www.cnylmz.net */ class html_rendele { /** * Bulunacak html etiketi * * @var string */ public $tag; /** * Okunacak adres * * @var string */ public $url; /** * Gönderilecek Referer Bilgisi * * @var string */ public $referer; /** * cookie.$cookie.txt şeklinde oluşturulacak cookie ismi * * @var string */ public $cookie; /** * Arama neticesinde bulanan tagları tutar * * @var array */ public $sonuc; /** * Aranan tag özelliklerini barındırır * * @var array */ private $ozellik; /** * Okunan sayfanın kodlarını barındırır * * @var string */ public $harman; /** * Hangi aşamada oldunduğuna yardımcı olur * * @var int */ private $durum; /** * Çalışma sırasındaki yapılanları saklar * * @var string */ public $log; /** * Tag hakkındaki geçici bilgiler tutulur * * @var array */ private $tag_temp; /** * Okunan sayfaya yollanacak post dizisi * * @var array */ public $post; /** * Okunan sayfaya gödnerilecek tarayıcı bilgisi * * @var string */ private $tarayici; /** * Kurucu metod */ function __construct(){ $this->tag=''; $this->tag_temp=array(); $this->url=null; $this->ozellik=array(); $this->sonuc=null; $this->durum=0; $this->log=''; $this->referer=null; $this->cookie=false; $this->post=array(); $this->tarayici='Googlebot/2.1 (+http://www.google.com/bot.html'; } /** * Kurucu metod tekrar çağırılırak bilgiler sıfırtlanır */ public function reset() { $this->__construct(); } /** * Adres okuma yerine html içeriğin direk eklenmesini sağlar * * @param string Daha önce okunmuş HTML içerik */ public function okunmus($kod_yigini) { if($this->durum > 0) $this->log.='Eski kaynak kodlarının üzerine yazılıyor!!!
'; $this->harman=$kod_yigini; $this->log.='Kaynak kodu elle girildi, link okunmuş sayılıyor
'; $this->durum=1; } /** * Gönderilecek tarayıcı header bilgisini oluşturur * * @param string tarayıcı türü */ public function tarayici($tarayici) { switch(strtolower($tarayici)) { case 'firefox': $this->tarayici='Mozilla/5.0 (Windows; U; Windows NT 5.1; tr; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10'; break; case 'ie': $this->tarayici='Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 1.1.4322)'; break; default: $this->tarayici='Googlebot/2.1 (+http://www.google.com/bot.html'; } } /** * url değişkeninde belirtilen adres okunur * * @return boolean */ public function oku() { if(empty($this->url)) { $this->log.='Adres Belirtilmemiş. Oku fonksiyonu başarısız
'; return false; } if(strpos($this->url,'http://')===false) { $this->url='http://'.$this->url; $this->log.='Adrese "http://" öneki eklendi
'; } $header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,"; $header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"; $header[] = "Cache-Control: max-age=0"; $header[] = "Connection: keep-alive"; $header[] = "Keep-Alive: 300"; $header[] = "Accept-Charset: ISO-8859-9,utf-8;q=0.7,*;q=0.7"; $header[] = "Accept-Language: tr-TR,tr;q=0.5"; $header[] = "Pragma: "; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $this->url); curl_setopt($curl, CURLOPT_USERAGENT, $this->tarayici); if($this->referer) { if(strpos($this->referer,'http://')===false) { $this->referer='http://'.$this->referer; $this->log.='Referer\'a http:// ön eki eklendi
'; } curl_setopt($curl, CURLOPT_REFERER, $this->referer); } else curl_setopt($curl, CURLOPT_REFERER, 'http://www.google.com'); if($this->cookie!==false) { $this->log.='COOKIE alımı açıldı
'; curl_setopt($curl, CURLOPT_COOKIEJAR, dirname(__FILE__).'/cookie.'.$this->cookie.'.txt'); curl_setopt($curl, CURLOPT_COOKIEFILE, dirname(__FILE__).'/cookie.'.$this->cookie.'.txt'); } if(count($this->post)>0) { curl_setopt($curl, CURLOPT_POST, 1); $yolla=array(); foreach($this->post as $name=>$value) { $yolla[]="$name=$value"; } if(count($yolla)>1) $yollanacak=implode('&',$yolla); else $yollanacak=$yolla; curl_setopt($curl, CURLOPT_POSTFIELDS,$yollanacak); } curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate'); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); ob_start(); $adres=curl_exec($curl); curl_close($curl); $this->harman = str_replace('/>','>',ob_get_contents()); ob_end_clean(); if($this->durum>0) $this->log.='Eski kaynak kodlarının üzerine yazılıyor!!!
'; $this->log.=$this->url.' linki okundu
'; $this->durum=1; return true; } /** * bulunacak tagın olması gereken özellikleri * * @param string filtrelenecek özeliğin adı * @param string elemanın istenilen değeri */ public function tag_ozellik($ozellik,$deger) { $this->ozellik[$ozellik]=$deger; } private function kapananbul($harman) { preg_match_all('/[\/|<]'.$this->tag.'([^>]*)>/si',$harman, $bulunanlar, PREG_SET_ORDER); $bulunan_s=count($bulunanlar); $say_acik=0; $kapanan_temp=array(); $ktemp['pos']=0; for($i=0;$i<$bulunan_s;$i++) { $ktemp['pos']=strpos($harman,$bulunanlar[$i][0],$ktemp['pos']); $temp['strlen']=strlen($bulunanlar[$i][0]); if(substr($bulunanlar[$i][0],0,1)=='<') { $ktemp['aciklar'][]=$i; $bulunanlar[$i]['pos_basla']=$ktemp['pos']+$temp['strlen']; } else if(substr($bulunanlar[$i][0],0,1)=='/') { @rsort($ktemp['aciklar']); $bulunanlar[$ktemp['aciklar'][0]]['pos_bit']=$ktemp['pos']-2; unset($ktemp['aciklar'][0],$bulunanlar[$i]); } $ktemp['pos']+=$temp['strlen']; } return $bulunanlar; } private function key_sirala(& $dizi) { if(is_array($dizi)==false) return FALSE; $temp=array(); foreach($dizi as $value) $temp[]=$value; $dizi=$temp; } private function ozellik_bul($harman){ $temp=explode(' ',trim($harman)); $temp_dizi=array(); for($k=0;$kdurum <1 ) { $this->log.='Henüz link okunmamış, cek fonksiyonu link okutuyor
'; if($this->oku()===false) return false; } $tag_ozellikler=$this->kapananbul($this->harman); $bulunan_s=count($tag_ozellikler); if($bulunan_s>0) { $this->key_sirala($tag_ozellikler); $this->log.=count($tag_ozellikler).' tane tag bulundu
'; for($i=0;$iozellik_bul($tag_ozellikler[$i][1]); $tag_temp['icerik']=substr($this->harman,$tag_ozellikler[$i]['pos_basla'],((isset($tag_ozellikler[$i]['pos_bit'])?$tag_ozellikler[$i]['pos_bit']:0)-$tag_ozellikler[$i]['pos_basla'])+1); $tag_ozellikler[$i]=$tag_temp; } } else { preg_match_all('@<([a-zA-Z0-9\n\t\s=\"\']*?)'.$this->tag.'(.*?)([/]?)>@is',$this->harman,$bulunanlar); $bulunan_s=count($bulunanlar[2]); if($bulunan_s>0) { $this->log.=$bulunan_s.' tane tag bulundu
'; $tag_ozellikler=array(); for($i=0;$i<$bulunan_s;$i++) { $ozellikler=preg_replace('@\s+@',' ',str_replace(array("\n","\t"),' ',$bulunanlar[2][$i])); $temp=explode(' ',trim($ozellikler)); for($k=0;$kdurum=2; $this->log.='Uygun tag bulunamadı'; return false; } } if(array_key_exists('*',$this->ozellik)) { $this->sonuc=$tag_ozellikler; $this->log.='Tüm taglar sonuc olarak verildi
'; return true; } if(array_key_exists('?',$this->ozellik)) { $temp=count($tag_ozellikler); for($i=0;$i<$temp;$i++) { if(array_search($this->ozellik['?'],$tag_ozellikler[$i])===false) { unset($tag_ozellikler[$i]); } } $this->log.='Özelliklerinden herhangi biri '.$this->ozellik['?'].' olmayan taglar elendi
'; unset($this->ozellik['?']); } $temp=count($tag_ozellikler); while(array_search('?',$this->ozellik)!==false) { $this->key_sirala($tag_ozellikler); $key=array_search('?',$this->ozellik); $temp=count($tag_ozellikler); for($i=0;$i<$temp;$i++) { if(is_array($tag_ozellikler[$i]) && array_key_exists($key,$tag_ozellikler[$i])===false) { unset($tag_ozellikler[$i]); } } $this->log.=$key.' özelliği olmayan taglar elendi
'; unset($this->ozellik[$key]); } $temp=count($this->ozellik); if($temp>0) { $tag_temp=$tag_ozellikler; $tag_ozellikler=array(); foreach($this->ozellik as $anahtar => $deger ) { for($i=0;$ilog.=''.$anahtar.' değeri '.$deger.' olmayan taglar elendi
'; } } $this->log.=count($tag_ozellikler).' adet uygun tag kaldı
'; $this->sonuc=$tag_ozellikler; $this->durum=2; return true; } } ?>