1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
| <?php
/**
* Fonction permettant d'utiliser l'album photo de Picassa
* @author Ryo Sensei
* @version 1.0
*
*/
class Picassa {
var $client;
/**
*
* @param unknown_type $photoId
*/
function showPhoto($photoId,$album){
?>
<div style="width:90%;margin-left:auto;margin-right:auto;margin-top:20px;text-align:center;border:1px solid blue;">
<img src="<?echo$photoId?>?imgmax=512">
</div>
<div style="width:90%;margin-left:auto;margin-right:auto;margin-top:2px;text-align:center;border:1px solid red;">
<table style="width:100%;"><tr>
<?php
$list = $this->getPhotos($album);
foreach($list as $k=>$photo){
if($photo["url"] == $photoId){
$key = $k;
}
}
if(($key-1)<0)$key=1;
for($i=$key-2;$i<=$key+2;$i++){
if(!isset($list[$i]))continue;
echo "<td><center><a href=?page=book&album=$album&photo=".$list[$i]["url"].">
<img src=".$list[$i]["thumbnail"].">
</a></center></td>";
}
?>
</tr></table>
</div>
<?php
}
/**
* Constructor
*
* @param unknown_type $client
* @return Picassa
*/
function Picassa($client){
$this->client = $client;
}
/**
* Retourne dans un tableau la liste des albums
*
* @param unknown_type $client
* @return array=>array(
* [text] => titre de l'album
* [thumbnail] => image de l'album
* [albumId] => identifiant de l'album
* )
*/
function getListAlbums($admin = false){
$client = $this->client;
$gp = new Zend_Gdata_Photos($client, "Google-DevelopersGuide-1.0");
try {
$userFeed = $gp->getUserFeed("default");
foreach ($userFeed as $userEntry) {
if(!$admin && $userEntry->gphotoAccess->text == "private")continue;
//print_r($userEntry);
$list[] = array("text"=>$userEntry->title->text,
"thumbnail"=>$userEntry->mediaGroup->thumbnail[0]->url,
"albumId"=>$userEntry->gphotoName->text);
}
} catch (Exception $e) {
echo "Error: " . $e->getMessage() . "<br />\n";
}
return $list;
}
/**
* Fonction permettant de récupérer la liste des photos d'un album
*
* @param unknown_type $album titre de l'album (identifiant)
* @param unknown_type $client
* @return array (
* array(
* [url] => url de la photo (version original)
* [titre] => titre de la photo (nom)
* [thumbnail] => miniature de la photo
* )
* )
*/
function getPhotos($album){
$client = $this->client;
$album = str_replace("_"," ",$album);
$gp = new Zend_Gdata_Photos($client, "Google-DevelopersGuide-1.0");
$query = $gp->newAlbumQuery();
$query->setUser("default");
$query->setAlbumName($album);
$albumFeed = $gp->getAlbumFeed($query);
foreach ($albumFeed as $albumEntry) {
//print_r($albumEntry);die;
//$photo["url"] = $albumEntry->mediaGroup->content[0]->url;
$mediaContentArray = $albumEntry->getMediaGroup()->getContent();
$photo["url"] = $mediaContentArray[0]->getUrl();
$photo["titre"] = $albumEntry->title->text;
$photo["thumbnail"] = $albumEntry->mediaGroup->thumbnail[0]->url;
$list[] = $photo;
}
return $list;
}
function randomPhoto(){
$gp = new Zend_Gdata_Photos($this->client, "Google-DevelopersGuide-1.0");
$query = $gp->newUserQuery();
// indicate the user's feed to retrieve
$query->setUser("default");
// set to only return photos
// the default kind value for a user feed is to include only albums
$query->setKind("photo");
$query->setMaxResults("1");
try {
// we're passing null for the username, as we want to send
// additional query parameters generated by the UserQuery class
$userFeed = $gp->getUserFeed(null, $query);
// because we specified 'photo' for the kind, only PhotoEntry objects
// will be contained in the UserFeed
foreach ($userFeed as $photoEntry) {
echo "<img src=\"".$photoEntry->mediaGroup->thumbnail[2]->url."\" width=100%>";
}
} catch (Zend_Gdata_App_HttpException $e) {
echo "Error: " . $e->getMessage() . "<br >\n";
if ($e->getResponse() != null) {
echo "Body: <br />\n" . $e->getResponse()->getBody() .
"<br />\n";
}
// In new versions of Zend Framework, you also have the option
// to print out the request that was made. As the request
// includes Auth credentials, it's not advised to print out
// this data unless doing debugging
// echo "Request: <br />\n" . $e->getRequest() . "<br />\n";
} catch (Zend_Gdata_App_Exception $e) {
echo "Error: " . $e->getMessage() . "<br />\n";
}
}
}
?> |
Partager