root/trunk/includes/Metalbum/dotnode.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_Dotnode extends Metalbum {
30    var $api;
31    var $username;
32    var $nsid;
33    var $nb_items;
34   
35    function Metalbum_Dotnode($username, $params) {
36        $params = array_merge(array('endpoint' => 'http://dotnode.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('dotnode.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, $format) {
58        switch($type) {
59            case 'thumb':
60                return "http://dotnode.com/dpics/100x100/{$path}.{$format}";
61                break;
62            case 'full':
63            default:    ;
64                return "http://dotnode.com/dpics/500x500/{$path}.{$format}";
65                break;
66        }
67    }
68
69    function getNbItems() {
70        if($this->nb_items) {
71            return $this->nb_items;
72        } else {
73            $response = $this->api->callMethod('dotnode.people.getNbPublicPhotos', array('user_id' => $this->nsid));
74            if ($response) {
75                $photos_node = $response->getNodeAt('photos');
76                $this->nb_items = $photos_node->getAttribute('total');
77                return $this->nb_items;
78            } else {
79                $this->_setError(__FUNCTION__, $this->api->getErrorCode(), $this->api->getErrorMessage());
80                return false;
81            }
82        }
83    }
84
85    function getPhotos($page=1, $per_page=15) {
86        $response = $this->api->callMethod('dotnode.people.getPublicPhotos', array(
87                    'user_id' => $this->nsid,
88                    'per_page' => $per_page,
89                    'page' => $page
90                    ));
91        if ($response) {
92            $photos_node = $response->getNodeAt('photos');
93            $this->nb_items = $photos_node->getAttribute('total');
94            $idx = 0;
95            // Must set the step to 2, because XML_Tree create node for line return in the XML (empty element)
96            for($idx=0; $idx < $per_page*2; $idx+=2) {
97                $photo_node = $photos_node->getElement(array($idx+1));
98                if(PEAR::isError($photo_node))
99                    break;
100                else {
101                    unset($photo);
102                    $path = $photo_node->getAttribute('path');
103                    $format = $photo_node->getAttribute('format');
104                    $photo['id'] = $photo_node->getAttribute('id');
105                    $photo['title'] = $photo_node->getAttribute('title');
106                    $photo['url_thumb'] = $this->_buildUrl('thumb', $path, $format);
107                    $photo['url_full'] = $this->_buildUrl('full', $path, $format);
108                    $rval[] = $photo;
109                }
110            }
111            return $rval;
112        } else {
113            $this->_setError(__FUNCTION__, $this->api->getErrorCode(), $this->api->getErrorMessage());
114            return false;
115        }
116    }
117
118
119    function getPhotoInfo($id_photo) {
120        $response = $this->api->callMethod('dotnode.photos.getInfo', array(
121                    'photo_id' => $id_photo
122                    ));
123        if ($response) {
124            $photo_node = $response->getNodeAt('photo');
125            $path = $photo_node->getAttribute('path');
126            $format = $photo_node->getAttribute('format');
127
128            $title_node = $photo_node->getNodeAt('title');
129            $info['title'] = $title_node->decodeXmlEntities($title_node->content);
130            $description_node = $photo_node->getNodeAt('description');
131            $info['description'] = $description_node->decodeXmlEntities($description_node->content);
132            $info['url_thumb'] = $this->_buildUrl('thumb', $path, $format);
133            $info['url_full'] = $this->_buildUrl('full', $path, $format);
134            return $info;
135        } else {
136            $this->_setError(__FUNCTION__, $this->api->getErrorCode(), $this->api->getErrorMessage());
137            return false;
138        }
139    }
140
141    function getUrlAlbum() {
142        return 'http://'.$this->username.'.dotnode.com/album';
143    }
144   
145}
146
147?>
Note: See TracBrowser for help on using the browser.