Current File : /home/aventura/public_html/facebook/phpcUrl.php |
<?php
class FacePageAlbum
{
private $URL;
private $TOKEN;
private $PAGE;
private $PHOTOS;
private function setPage()
{
$protocol = $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
$this->PAGE = $protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
}
private function setAlbumUrl($id)
{
if(is_numeric($id))
{
if($this->TOKEN)
{
$this->URL = "http://graph.facebook.com/".$id."/albums?".$this->TOKEN;
return true;
}
else
{
$this->URL = "http://graph.facebook.com/".$id."/albums";
return true;
}
}
else
{
return false;
}
}
private function setToken($appId, $appSecret)
{
$this->TOKEN = $this->curlGetFile('https://graph.facebook.com/oauth/access_token?type=client_cred&client_id='.$appId.'&client_secret='.$appSecret);
}
public function FacePageAlbum($id, $albumId, $aurl, $appId, $appSecret, $var_album)
{
$html="";
$this->setPage();
if($id)
{
if($appId && $appSecret)
$this->setToken($appId, $appSecret);
$this->setAlbumUrl($id);
if($albumId && $this->albumChk($albumId))
{
$this->PHOTOS = 'http://graph.facebook.com/v1.0/'.$albumId.'/photos';
$prueba= $this->curlGetFile($this->PHOTOS);
//echo "a ".$prueba;
$json = json_decode($prueba);
if($json -> error) die("THERE HAS BEEN AN ERROR:album id invalid");
$html.= '<a id="back" href="javascript:history.go(-1)">Go Back</a>';
$html.= '<a id="backAlbums" href="'.$this->PAGE.'">Back to albums</a>';
$html.= '<br clear="all" />';
if($json->paging->previous)
$html.= '<a id="prev" href="'.$PAGE.'?aurl='.urlencode($json->paging->previous).'">Previous</a>';
if($json->paging->next)
$html.= '<a id="next" href="'.$PAGE.'?aurl='.urlencode($json->paging->next).'">Next</a>';
$html.= '<br clear="all" />';
foreach($json->data as $v)
{
$html.= "<a class='ImageLink' href = '".$v->source."'><img width='110px' src='".$v->picture."' /></a>";
}
echo $html;
return true;
}
else if ($aurl)
{
$this->PHOTOS = urldecode($aurl);
$json = json_decode($this->curlGetFile($this->PHOTOS));
if($json -> error) die("THERE HAS BEEN AN ERROR: album url invalid");
echo '<a id="back" href="javascript:history.go(-1)">Go Back</a>';
echo '<a id="backAlbums" href="'.$this->PAGE.'">Back to albums</a>';
echo '<br clear="all" />';
if($json->paging->previous)
echo '<a id="prev" href="'.$PAGE.'?aurl='.urlencode($json->paging->previous).'">Previous</a>';
if($json->paging->next)
echo '<a id="next" href="'.$PAGE.'?aurl='.urlencode($json->paging->next).'">Next</a>';
echo '<br clear="all" />';
foreach($json->data as $v)
{
echo "<a class='ImageLink' href = '".$v->source."'><img width='110px' src='".$v->picture."' /></a>";
}
return true;
}
else if ($var_album)
{
$json = json_decode($this->curlGetFile($this->URL));
if($json -> error) die("THERE HAS BEEN AN ERROR: pageId invalid");
foreach($json->data as $v)
{
$album=split(",",$var_album);
while ($datos_album = current($album))
{
//echo "prueba".$datos_album;
$detalle="";
if ($v->id==$datos_album)
{
/*echo "<div class ='ImgWrapper'>";
echo "<div style = 'width:125px; height:120px;overflow:hidden'>
<img width='125px' src='https://graph.facebook.com/".$v->id."/picture' />
</div>";
echo $v->from->name."<br>";
echo "<a href = '".$this->PAGE;
echo "?";
echo "aid=".$v->id."'>".$v->name."</a>";
echo "<br>Num of images:".$v->count."<br>";
echo "<br clear='all'></div>";*/
$detalle.="src='https://graph.facebook.com/".$v->id."/picture'"."<br>";
$detalle.=$v->from->name."<br>";
$detalle.=$v->name."<br>";
$detalle.=$v->count."<br>";
//echo $detalle;
}
next($album);
}
}
return $detalle;
}
else
{
$json = json_decode($this->curlGetFile($this->URL));
if($json -> error) die("THERE HAS BEEN AN ERROR: pageId invalid");
foreach($json->data as $v)
{
echo "<div class ='ImgWrapper'>";
echo "<div style = 'width:125px; height:120px;overflow:hidden'>
<img width='125px' src='https://graph.facebook.com/".$v->id."/picture' />
</div>";
echo $v->from->name."<br>";
echo "<a href = '".$this->PAGE;
echo "?";
echo "aid=".$v->id."'>".$v->name."</a>";
echo "<br>Num of images:".$v->count."<br>";
echo "<br clear='all'></div>";
}
return true;
}
}
return false;
}
public function curlGetFile($curlUrl)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $curlUrl);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
public function albumChk($albumId)
{
$json = json_decode($this->curlGetFile($this->URL));
$arrayId = array();
foreach($json->data as $v)
array_push($arrayId, $v->id);
if(!in_array($albumId,$arrayId)) return false;
return true;
}
};
?>