Current File : /home/aventura/public_html/facebook/mifacebook.php
<?php
		function setPage()
		{
				$protocol = $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
				$PAGE = $protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
			  	return $PAGE;
		}

		function setAlbumUrl($id)
		{
			if(is_numeric($id))
			{
				if($TOKEN )
				{
					$URL = "http://graph.facebook.com/".$id."/albums?limit=500".$TOKEN ;
					return $URL;
				}
				else
				{
					$URL = "http://graph.facebook.com/".$id."/albums?limit=500";
					return $URL;				
				}
			}
			else
			{
				return false;
			}
		}
		function setToken($appId, $appSecret)
		{
			$TOKEN = curlGetFile('https://graph.facebook.com/oauth/access_token?type=client_cred&client_id='.$appId.'&client_secret='.$appSecret);
			return $TOKEN;
		}
		
		function FacePageAlbum($id, $albumId, $aurl, $appId, $appSecret, $var_album)
		{
			$html="";
			$PAGE=setPage();
			if($id)
			{
				if($appId && $appSecret)
					$TOKEN=setToken($appId, $appSecret);
					$URL=setAlbumUrl($id);
				if($albumId)
				{
					
					$PHOTOS = 'http://graph.facebook.com/v1.0/'.$albumId.'/photos';
					$prueba= curlGetFile($PHOTOS);

					$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="'.$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)
				{
					$PHOTOS = urldecode($aurl);
					$json  = json_decode(curlGetFile($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="'.$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)
				{
					//echo $var_album;
					$json = json_decode(curlGetFile($URL));
					if($json -> error) die("THERE HAS BEEN AN ERROR: pageId invalid");
					$detalle="";
					foreach($json->data as $v)
					{
						$album=split(",",$var_album);
						while ($datos_album = current($album)) 
						{
							echo $v->id ." ".$datos_album."<br>";
							if ($v->id==$datos_album)
							{
								$detalle.=$v->id."<@>";
								$detalle.="https://graph.facebook.com/".$v->id."/picture"."<@>";
								$detalle.=utf8_decode($v->from->name)."<@>";
								$detalle.=utf8_decode($v->name)."<@>";
								$detalle.=$v->count."<br>";
							}
							next($album);
						}
					}
					return $detalle;
				}
				else
				{
					$json = json_decode(curlGetFile($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 = '".$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;
		}
		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;
		}
		
		function albumChk($albumId)
		{
			$URL2=$albumId;		
			echo $URL2;
			$json = json_decode(curlGetFile($URL2));
			$arrayId = array();
			foreach($json->data as $v)
						array_push($arrayId, $v->id);
			if(!in_array($albumId,$arrayId)) return false;
			return true;
		}
//};
?>