Yet another useless crappy code

Uglavnom klijent je na Facebooku napravio profile za svoju firmu a ne page. Pošto ovo ne može da se odradi preko API bez tokena, urađen je klasični scrapping javnog profila (ovo funkcioniše samo ako su "prijatelji" vidljivi).
PHP kôd:
class Profiler{
public function display($id){
$api = $this->curl("https://graph.facebook.com/$id");
$api = json_decode($api, true);
$url = $api["link"];
$html = $this->curl($url);
$html = preg_replace("#(\\\u[a-fA-F0-9]{4})#e", "chr(hexdec('\\1'))", $html);
$html = stripslashes($html);
preg_match_all('#tabindex="-1"><img class="img" src="http://profile.ak.fbcdn.net/(.*?)" alt="(.*?)" />#is', $html, $matches);
unset($matches[0]);
$count = count($matches[1]);
for($i = 0; $i < $count; $i++){
$img .= '<div><img alt="" width="50px" height="50px" src="http://profile.ak.fbcdn.net/'.$matches[1][$i].'"/><p>'.$matches[2][$i].'</p></div>';
}
return '
<div id="facebook">
<h1 class="profile"><img alt="" src="https://graph.facebook.com/'.$id.'/picture"/> <a href="'.$api["link"].'" target="_blank">'.$api["name"].' @ Facebook</a></h1>
<div class="friends">'.$img.'</div>
</div>';
}
private function curl($url, $nobody = false){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if($nobody == true){
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
}
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
}
PHP kôd:
$fb = new Profiler;
echo $fb->display("100000414144463");
Ovdje možete vidjeti učitavanje preko AJAX...
http://cacfolija.ba/