| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | require_once 'Flickr/API.php'; |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | class Metalbum_Interalbum extends Metalbum { |
|---|
| 30 | var $api; |
|---|
| 31 | var $username; |
|---|
| 32 | var $nsid; |
|---|
| 33 | var $nb_items; |
|---|
| 34 | |
|---|
| 35 | function Metalbum_Interalbum($username, $params) { |
|---|
| 36 | $params = array_merge(array('endpoint' => 'http://interalbum.com/api/rest'), $params); |
|---|
| 37 | $this->api =& new Flickr_API($params); |
|---|
| 38 | if(!$this->_setUsername($username)) |
|---|
| 39 | $this->status = 'error'; |
|---|
| 40 | else |
|---|
| 41 | $this->status = 'ok'; |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | function _setUsername($username) { |
|---|
| 45 | $response = $this->api->callMethod('interalbum.people.findByUsername', array('username' => $username)); |
|---|
| 46 | if ($response) { |
|---|
| 47 | $this->username = $username; |
|---|
| 48 | $user_node = $response->getNodeAt('user'); |
|---|
| 49 | $this->nsid = $user_node->getAttribute('nsid'); |
|---|
| 50 | return $this->nsid; |
|---|
| 51 | } else { |
|---|
| 52 | $this->_setError(__FUNCTION__, $this->api->getErrorCode(), $this->api->getErrorMessage()); |
|---|
| 53 | return false; |
|---|
| 54 | } |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | function _buildUrl($type, $path) { |
|---|
| 58 | switch($type) { |
|---|
| 59 | case 'thumb': $format='100x100'; break; |
|---|
| 60 | case 'full': |
|---|
| 61 | default: $format='500x500'; break; |
|---|
| 62 | } |
|---|
| 63 | return "http://interalbum.com/dpics/{$format}/{$path}"; |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | function getNbItems() { |
|---|
| 67 | if($this->nb_items) { |
|---|
| 68 | return $this->nb_items; |
|---|
| 69 | } else { |
|---|
| 70 | $response = $this->api->callMethod('interalbum.people.getNbPublicPhotos', array('user_id' => $this->nsid)); |
|---|
| 71 | if ($response) { |
|---|
| 72 | $photos_node = $response->getNodeAt('photos'); |
|---|
| 73 | $this->nb_items = $photos_node->getAttribute('total'); |
|---|
| 74 | return $this->nb_items; |
|---|
| 75 | } else { |
|---|
| 76 | $this->_setError(__FUNCTION__, $this->api->getErrorCode(), $this->api->getErrorMessage()); |
|---|
| 77 | return false; |
|---|
| 78 | } |
|---|
| 79 | } |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | function getPhotos($page=1, $per_page=15) { |
|---|
| 83 | $response = $this->api->callMethod('interalbum.people.getPublicPhotos', array( |
|---|
| 84 | 'user_id' => $this->nsid, |
|---|
| 85 | 'per_page' => $per_page, |
|---|
| 86 | 'page' => $page |
|---|
| 87 | )); |
|---|
| 88 | if ($response) { |
|---|
| 89 | $photos_node = $response->getNodeAt('photos'); |
|---|
| 90 | $this->nb_items = $photos_node->getAttribute('total'); |
|---|
| 91 | $idx = 0; |
|---|
| 92 | |
|---|
| 93 | for($idx=0; $idx < $per_page*2; $idx+=2) { |
|---|
| 94 | $photo_node = $photos_node->getElement(array($idx+1)); |
|---|
| 95 | if(PEAR::isError($photo_node)) |
|---|
| 96 | break; |
|---|
| 97 | else { |
|---|
| 98 | unset($photo); |
|---|
| 99 | $path = $photo_node->getAttribute('path'); |
|---|
| 100 | $photo['id'] = $photo_node->getAttribute('id'); |
|---|
| 101 | $photo['title'] = $photo_node->getAttribute('title'); |
|---|
| 102 | $photo['url_thumb'] = $this->_buildUrl('thumb', $path); |
|---|
| 103 | $photo['url_full'] = $this->_buildUrl('full', $path); |
|---|
| 104 | $rval[] = $photo; |
|---|
| 105 | } |
|---|
| 106 | } |
|---|
| 107 | return $rval; |
|---|
| 108 | } else { |
|---|
| 109 | $this->_setError(__FUNCTION__, $this->api->getErrorCode(), $this->api->getErrorMessage()); |
|---|
| 110 | return false; |
|---|
| 111 | } |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | function getPhotoInfo($id_photo) { |
|---|
| 116 | $response = $this->api->callMethod('interalbum.photos.getInfo', array( |
|---|
| 117 | 'photo_id' => $id_photo |
|---|
| 118 | )); |
|---|
| 119 | if ($response) { |
|---|
| 120 | $photo_node = $response->getNodeAt('photo'); |
|---|
| 121 | $path = $photo_node->getAttribute('path'); |
|---|
| 122 | |
|---|
| 123 | $title_node = $photo_node->getNodeAt('title'); |
|---|
| 124 | $info['title'] = $title_node->decodeXmlEntities($title_node->content); |
|---|
| 125 | $description_node = $photo_node->getNodeAt('description'); |
|---|
| 126 | $info['description'] = $description_node->decodeXmlEntities($description_node->content); |
|---|
| 127 | $info['url_thumb'] = $this->_buildUrl('thumb', $path); |
|---|
| 128 | $info['url_full'] = $this->_buildUrl('full', $path); |
|---|
| 129 | return $info; |
|---|
| 130 | } else { |
|---|
| 131 | $this->_setError(__FUNCTION__, $this->api->getErrorCode(), $this->api->getErrorMessage()); |
|---|
| 132 | return false; |
|---|
| 133 | } |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | function getUrlAlbum() { |
|---|
| 137 | return 'http://'.$this->username.'.interalbum.com/'; |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | ?> |
|---|