|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00027 require_once 'Zend/Gdata.php'; 00028 00032 require_once 'Zend/Gdata/Photos/UserFeed.php'; 00033 00037 require_once 'Zend/Gdata/Photos/AlbumFeed.php'; 00038 00042 require_once 'Zend/Gdata/Photos/PhotoFeed.php'; 00043 00058 class Zend_Gdata_Photos extends Zend_Gdata 00059 { 00060 00061 const PICASA_BASE_URI = 'http://picasaweb.google.com/data'; 00062 const PICASA_BASE_FEED_URI = 'http://picasaweb.google.com/data/feed'; 00063 const AUTH_SERVICE_NAME = 'lh2'; 00064 00068 const DEFAULT_PROJECTION = 'api'; 00069 00073 const DEFAULT_VISIBILITY = 'all'; 00074 00078 const DEFAULT_USER = 'default'; 00079 00083 const USER_PATH = 'user'; 00084 00088 const ALBUM_PATH = 'albumid'; 00089 00093 const PHOTO_PATH = 'photoid'; 00094 00098 const COMMUNITY_SEARCH_PATH = 'all'; 00099 00103 const FEED_LINK_PATH = 'http://schemas.google.com/g/2005#feed'; 00104 00108 const KIND_PATH = 'http://schemas.google.com/g/2005#kind'; 00109 00115 public static $namespaces = array( 00116 array('gphoto', 'http://schemas.google.com/photos/2007', 1, 0), 00117 array('photo', 'http://www.pheed.com/pheed/', 1, 0), 00118 array('exif', 'http://schemas.google.com/photos/exif/2007', 1, 0), 00119 array('georss', 'http://www.georss.org/georss', 1, 0), 00120 array('gml', 'http://www.opengis.net/gml', 1, 0), 00121 array('media', 'http://search.yahoo.com/mrss/', 1, 0) 00122 ); 00123 00131 public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0') 00132 { 00133 $this->registerPackage('Zend_Gdata_Photos'); 00134 $this->registerPackage('Zend_Gdata_Photos_Extension'); 00135 parent::__construct($client, $applicationId); 00136 $this->_httpClient->setParameterPost('service', self::AUTH_SERVICE_NAME); 00137 } 00138 00150 public function getUserFeed($userName = null, $location = null) 00151 { 00152 if ($location instanceof Zend_Gdata_Photos_UserQuery) { 00153 $location->setType('feed'); 00154 if ($userName !== null) { 00155 $location->setUser($userName); 00156 } 00157 $uri = $location->getQueryUrl(); 00158 } else if ($location instanceof Zend_Gdata_Query) { 00159 if ($userName !== null) { 00160 $location->setUser($userName); 00161 } 00162 $uri = $location->getQueryUrl(); 00163 } else if ($location !== null) { 00164 $uri = $location; 00165 } else if ($userName !== null) { 00166 $uri = self::PICASA_BASE_FEED_URI . '/' . 00167 self::DEFAULT_PROJECTION . '/' . self::USER_PATH . '/' . 00168 $userName; 00169 } else { 00170 $uri = self::PICASA_BASE_FEED_URI . '/' . 00171 self::DEFAULT_PROJECTION . '/' . self::USER_PATH . '/' . 00172 self::DEFAULT_USER; 00173 } 00174 00175 return parent::getFeed($uri, 'Zend_Gdata_Photos_UserFeed'); 00176 } 00177 00187 public function getAlbumFeed($location = null) 00188 { 00189 if ($location === null) { 00190 require_once 'Zend/Gdata/App/InvalidArgumentException.php'; 00191 throw new Zend_Gdata_App_InvalidArgumentException( 00192 'Location must not be null'); 00193 } else if ($location instanceof Zend_Gdata_Photos_UserQuery) { 00194 $location->setType('feed'); 00195 $uri = $location->getQueryUrl(); 00196 } else if ($location instanceof Zend_Gdata_Query) { 00197 $uri = $location->getQueryUrl(); 00198 } else { 00199 $uri = $location; 00200 } 00201 return parent::getFeed($uri, 'Zend_Gdata_Photos_AlbumFeed'); 00202 } 00203 00215 public function getPhotoFeed($location = null) 00216 { 00217 if ($location === null) { 00218 $uri = self::PICASA_BASE_FEED_URI . '/' . 00219 self::DEFAULT_PROJECTION . '/' . 00220 self::COMMUNITY_SEARCH_PATH; 00221 } else if ($location instanceof Zend_Gdata_Photos_UserQuery) { 00222 $location->setType('feed'); 00223 $uri = $location->getQueryUrl(); 00224 } else if ($location instanceof Zend_Gdata_Query) { 00225 $uri = $location->getQueryUrl(); 00226 } else { 00227 $uri = $location; 00228 } 00229 return parent::getFeed($uri, 'Zend_Gdata_Photos_PhotoFeed'); 00230 } 00231 00240 public function getUserEntry($location) 00241 { 00242 if ($location === null) { 00243 require_once 'Zend/Gdata/App/InvalidArgumentException.php'; 00244 throw new Zend_Gdata_App_InvalidArgumentException( 00245 'Location must not be null'); 00246 } else if ($location instanceof Zend_Gdata_Photos_UserQuery) { 00247 $location->setType('entry'); 00248 $uri = $location->getQueryUrl(); 00249 } else if ($location instanceof Zend_Gdata_Query) { 00250 $uri = $location->getQueryUrl(); 00251 } else { 00252 $uri = $location; 00253 } 00254 return parent::getEntry($uri, 'Zend_Gdata_Photos_UserEntry'); 00255 } 00256 00265 public function getAlbumEntry($location) 00266 { 00267 if ($location === null) { 00268 require_once 'Zend/Gdata/App/InvalidArgumentException.php'; 00269 throw new Zend_Gdata_App_InvalidArgumentException( 00270 'Location must not be null'); 00271 } else if ($location instanceof Zend_Gdata_Photos_UserQuery) { 00272 $location->setType('entry'); 00273 $uri = $location->getQueryUrl(); 00274 } else if ($location instanceof Zend_Gdata_Query) { 00275 $uri = $location->getQueryUrl(); 00276 } else { 00277 $uri = $location; 00278 } 00279 return parent::getEntry($uri, 'Zend_Gdata_Photos_AlbumEntry'); 00280 } 00281 00290 public function getPhotoEntry($location) 00291 { 00292 if ($location === null) { 00293 require_once 'Zend/Gdata/App/InvalidArgumentException.php'; 00294 throw new Zend_Gdata_App_InvalidArgumentException( 00295 'Location must not be null'); 00296 } else if ($location instanceof Zend_Gdata_Photos_UserQuery) { 00297 $location->setType('entry'); 00298 $uri = $location->getQueryUrl(); 00299 } else if ($location instanceof Zend_Gdata_Query) { 00300 $uri = $location->getQueryUrl(); 00301 } else { 00302 $uri = $location; 00303 } 00304 return parent::getEntry($uri, 'Zend_Gdata_Photos_PhotoEntry'); 00305 } 00306 00315 public function getTagEntry($location) 00316 { 00317 if ($location === null) { 00318 require_once 'Zend/Gdata/App/InvalidArgumentException.php'; 00319 throw new Zend_Gdata_App_InvalidArgumentException( 00320 'Location must not be null'); 00321 } else if ($location instanceof Zend_Gdata_Photos_UserQuery) { 00322 $location->setType('entry'); 00323 $uri = $location->getQueryUrl(); 00324 } else if ($location instanceof Zend_Gdata_Query) { 00325 $uri = $location->getQueryUrl(); 00326 } else { 00327 $uri = $location; 00328 } 00329 return parent::getEntry($uri, 'Zend_Gdata_Photos_TagEntry'); 00330 } 00331 00340 public function getCommentEntry($location) 00341 { 00342 if ($location === null) { 00343 require_once 'Zend/Gdata/App/InvalidArgumentException.php'; 00344 throw new Zend_Gdata_App_InvalidArgumentException( 00345 'Location must not be null'); 00346 } else if ($location instanceof Zend_Gdata_Photos_UserQuery) { 00347 $location->setType('entry'); 00348 $uri = $location->getQueryUrl(); 00349 } else if ($location instanceof Zend_Gdata_Query) { 00350 $uri = $location->getQueryUrl(); 00351 } else { 00352 $uri = $location; 00353 } 00354 return parent::getEntry($uri, 'Zend_Gdata_Photos_CommentEntry'); 00355 } 00356 00370 public function insertAlbumEntry($album, $uri = null) 00371 { 00372 if ($uri === null) { 00373 $uri = self::PICASA_BASE_FEED_URI . '/' . 00374 self::DEFAULT_PROJECTION . '/' . self::USER_PATH . '/' . 00375 self::DEFAULT_USER; 00376 } 00377 $newEntry = $this->insertEntry($album, $uri, 'Zend_Gdata_Photos_AlbumEntry'); 00378 return $newEntry; 00379 } 00380 00393 public function insertPhotoEntry($photo, $uri = null) 00394 { 00395 if ($uri instanceof Zend_Gdata_Photos_AlbumEntry) { 00396 $uri = $uri->getLink(self::FEED_LINK_PATH)->href; 00397 } 00398 if ($uri === null) { 00399 require_once 'Zend/Gdata/App/InvalidArgumentException.php'; 00400 throw new Zend_Gdata_App_InvalidArgumentException( 00401 'URI must not be null'); 00402 } 00403 $newEntry = $this->insertEntry($photo, $uri, 'Zend_Gdata_Photos_PhotoEntry'); 00404 return $newEntry; 00405 } 00406 00419 public function insertTagEntry($tag, $uri = null) 00420 { 00421 if ($uri instanceof Zend_Gdata_Photos_PhotoEntry) { 00422 $uri = $uri->getLink(self::FEED_LINK_PATH)->href; 00423 } 00424 if ($uri === null) { 00425 require_once 'Zend/Gdata/App/InvalidArgumentException.php'; 00426 throw new Zend_Gdata_App_InvalidArgumentException( 00427 'URI must not be null'); 00428 } 00429 $newEntry = $this->insertEntry($tag, $uri, 'Zend_Gdata_Photos_TagEntry'); 00430 return $newEntry; 00431 } 00432 00446 public function insertCommentEntry($comment, $uri = null) 00447 { 00448 if ($uri instanceof Zend_Gdata_Photos_PhotoEntry) { 00449 $uri = $uri->getLink(self::FEED_LINK_PATH)->href; 00450 } 00451 if ($uri === null) { 00452 require_once 'Zend/Gdata/App/InvalidArgumentException.php'; 00453 throw new Zend_Gdata_App_InvalidArgumentException( 00454 'URI must not be null'); 00455 } 00456 $newEntry = $this->insertEntry($comment, $uri, 'Zend_Gdata_Photos_CommentEntry'); 00457 return $newEntry; 00458 } 00459 00471 public function deleteAlbumEntry($album, $catch) 00472 { 00473 if ($catch) { 00474 try { 00475 $this->delete($album); 00476 } catch (Zend_Gdata_App_HttpException $e) { 00477 if ($e->getResponse()->getStatus() === 409) { 00478 $entry = new Zend_Gdata_Photos_AlbumEntry($e->getResponse()->getBody()); 00479 $this->delete($entry->getLink('edit')->href); 00480 } else { 00481 throw $e; 00482 } 00483 } 00484 } else { 00485 $this->delete($album); 00486 } 00487 } 00488 00500 public function deletePhotoEntry($photo, $catch) 00501 { 00502 if ($catch) { 00503 try { 00504 $this->delete($photo); 00505 } catch (Zend_Gdata_App_HttpException $e) { 00506 if ($e->getResponse()->getStatus() === 409) { 00507 $entry = new Zend_Gdata_Photos_PhotoEntry($e->getResponse()->getBody()); 00508 $this->delete($entry->getLink('edit')->href); 00509 } else { 00510 throw $e; 00511 } 00512 } 00513 } else { 00514 $this->delete($photo); 00515 } 00516 } 00517 00529 public function deleteCommentEntry($comment, $catch) 00530 { 00531 if ($catch) { 00532 try { 00533 $this->delete($comment); 00534 } catch (Zend_Gdata_App_HttpException $e) { 00535 if ($e->getResponse()->getStatus() === 409) { 00536 $entry = new Zend_Gdata_Photos_CommentEntry($e->getResponse()->getBody()); 00537 $this->delete($entry->getLink('edit')->href); 00538 } else { 00539 throw $e; 00540 } 00541 } 00542 } else { 00543 $this->delete($comment); 00544 } 00545 } 00546 00558 public function deleteTagEntry($tag, $catch) 00559 { 00560 if ($catch) { 00561 try { 00562 $this->delete($tag); 00563 } catch (Zend_Gdata_App_HttpException $e) { 00564 if ($e->getResponse()->getStatus() === 409) { 00565 $entry = new Zend_Gdata_Photos_TagEntry($e->getResponse()->getBody()); 00566 $this->delete($entry->getLink('edit')->href); 00567 } else { 00568 throw $e; 00569 } 00570 } 00571 } else { 00572 $this->delete($tag); 00573 } 00574 } 00575 00576 }