root/trunk/includes/Metalbum/flickr.class.php

Revision 27, 4.7 KB (checked in by alexx, 7 years ago)
  • Add support for .node album in Meta album (not usefull for dotnode.com user, but good for other "Open .node" installation that want to import dotnode.com album)
  • Add REST api to access .node Album (must be extented later with other module of .node)
  • Add forgotten icons for meta album
  • Add dPics scripts to automagicaly resize requested image with size put in his url (<dpics script>/500x400/<file_path>.jpg => give you <file_path>.jpg in 500x400)
Line 
1<?php
2/****************************************************** Open .node ***
3 * Description:   
4 * Status:        Stable.
5 * Author:        Alexandre Dath <alexandre@dotnode.com>
6 * $Id$
7 *
8 * Copyright (C) 2005 Alexandre Dath <alexandre@dotnode.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 ******************** http://opensource.ikse.net/projects/dotnode ***/
24
25require_once 'Flickr/API.php';
26
27# create a new api object
28
29class Metalbum_Flickr extends Metalbum {
30    var $api;
31    var $username;
32    var $nsid;
33    var $nb_items;
34   
35    function Metalbum_Flickr($username, $params) {
36        $this->api =& new Flickr_API($params);
37        if(!$this->_setUsername($username))
38            $this->status = 'error';
39        else
40            $this->status = 'ok';
41    }
42
43    function _setUsername($username) {
44        $response = $this->api->callMethod('flickr.people.findByUsername', array('username' => $username));
45        if ($response) {
46            $this->username = $username;
47            $user_node $response->getNodeAt('user');
48            $this->nsid = $user_node->getAttribute('nsid');
49            return $this->nsid;
50        } else {
51            $this->_setError(__FUNCTION__, $this->api->getErrorCode(), $this->api->getErrorMessage());
52            return false;
53        }
54    }
55
56    function _buildUrl($type, $server, $secret, $id) {
57        switch($type) {
58            case 'thumb':    $format='_t'; break;
59            case 'full':
60            default:    $format=''; break;
61        }
62        return "http://photos{$server}.flickr.com/{$id}_{$secret}{$format}.jpg";
63    }
64
65    function getNbItems() {
66        if($this->nb_items) {
67            return $this->nb_items;
68        } else {
69            $response = $this->api->callMethod('flickr.people.getPublicPhotos', array('user_id' => $this->nsid));
70            if ($response) {
71                $photos_node = $response->getNodeAt('photos');
72                $this->nb_items = $photos_node->getAttribute('total');
73                return $this->nb_items;
74            } else {
75                $this->_setError(__FUNCTION__, $this->api->getErrorCode(), $this->api->getErrorMessage());
76                return false;
77            }
78        }
79    }
80
81    function getPhotos($page=1, $per_page=15) {
82        $response = $this->api->callMethod('flickr.people.getPublicPhotos', array(
83                    'user_id' => $this->nsid,
84                    'per_page' => $per_page,
85                    'page' => $page
86                    ));
87        if ($response) {
88            $photos_node = $response->getNodeAt('photos');
89            $this->nb_items = $photos_node->getAttribute('total');
90            $idx = 0;
91            // Must set the step to 2, because XML_Tree create node for line return in the XML (empty element)
92            for($idx=0; $idx < $per_page*2; $idx+=2) {
93                $photo_node = $photos_node->getElement(array($idx+1));
94                if(PEAR::isError($photo_node))
95                    break;
96                else {
97                    unset($photo);
98                    $id = $photo_node->getAttribute('id');
99                    $server = $photo_node->getAttribute('server');
100                    $secret = $photo_node->getAttribute('secret');
101                    $photo['id'] = $id;
102                    $photo['title'] = $photo_node->getAttribute('title');
103                    $photo['url_thumb'] = $this->_buildUrl('thumb', $server, $secret, $id);
104                    $photo['url_full'] = $this->_buildUrl('full', $server, $secret, $id);
105                    $rval[] = $photo;
106                }
107            }
108            return $rval;
109        } else {
110            $this->_setError(__FUNCTION__, $this->api->getErrorCode(), $this->api->getErrorMessage());
111            return false;
112        }
113    }
114
115
116    function getPhotoInfo($id_photo) {
117        $response = $this->api->callMethod('flickr.photos.getInfo', array(
118                    'photo_id' => $id_photo
119                    ));
120        if ($response) {
121            $photo_node = $response->getNodeAt('photo');
122            $id = $photo_node->getAttribute('id');
123            $secret = $photo_node->getAttribute('secret');
124            $server = $photo_node->getAttribute('server');
125
126            $title_node = $photo_node->getNodeAt('title');
127            $info['title'] = $title_node->decodeXmlEntities($title_node->content);
128            $description_node = $photo_node->getNodeAt('description');
129            $info['description'] = $description_node->decodeXmlEntities($description_node->content);
130            $info['url_thumb'] = $this->_buildUrl('thumb', $server, $secret, $id);
131            $info['url_full'] = $this->_buildUrl('full', $server, $secret, $id);
132            return $info;
133        } else {
134            $this->_setError(__FUNCTION__, $this->api->getErrorCode(), $this->api->getErrorMessage());
135            return false;
136        }
137    }
138
139    function getUrlAlbum() {
140        return 'http://flickr.com/photos/'.$this->nsid.'/';
141    }
142   
143}
144
145?>
Note: See TracBrowser for help on using the browser.