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

Revision 27, 4.5 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_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            // Must set the step to 2, because XML_Tree create node for line return in the XML (empty element)
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?>
Note: See TracBrowser for help on using the browser.