forked from zikula-modules/Mediashare
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpnextapp_picasaapi.php
126 lines (107 loc) · 4 KB
/
pnextapp_picasaapi.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
// $Id$
//
// Mediashare by Jorn Lind-Nielsen (C)
//
require_once 'modules/mediashare/common.php';
require_once 'modules/mediashare/pnincludes/phpPicasa/Picasa.php';
class MediasharePicasaAlbum extends MediashareBaseAlbum
{
var $picasaApi;
function MediasharePicasaAlbum($albumId, $albumData)
{
$albumData['allowMediaEdit'] = false;
$this->albumId = $albumId;
$this->albumData = $albumData;
}
function getApi()
{
if ($this->picasaApi == null) {
$APIKey = pnModGetVar('mediashare', 'picasaAPIKey');
$this->picasaApi = new Picasa($APIKey);
}
return $this->picasaApi;
}
function getMediaItems()
{
if (($images = $this->getRawImages()) === false) {
return false;
}
for ($i = 0, $cou = count($images); $i < $cou; ++$i) {
$images[$i] = $this->convertImage($images[$i]);
}
$this->fixMainMedia($images);
return $images;
}
function getRawImages()
{
$dom = ZLanguage::getModuleDomain('mediashare');
$data = $this->albumData['extappData']['data'];
try {
if (!empty($data['userName']) && empty($data['albumName'])) {
$images = $this->getApi()->getImages($data['userName'], 30, 0, null, null, 'public', '72,400', 800)->getImages();
} else if (!empty($data['userName']) && !empty($data['albumName'])) {
$images = $this->getApi()->getAlbumByName($data['userName'], $data['albumName'], 30, 0, null, null, '72,400', 800, $data['authkey'])->getImages();
}
} catch (Exception $e) {
return LogUtil::registerError(__('The supplied URL resulted in an error.', $dom));
}
return $images;
}
function convertImage(&$image)
{
$thumbUrlMap = $image->getThumbUrlMap();
$image = array(
'id' => (string) $image->getIdNum(),
'ownerId' => null,
'createdDate' => null,
'modifiedDate' => null,
'title' => $image->getTitle(),
'keywordsArray' => $image->getTags(),
'hasKeywords' => count($image->getTags()) > 0,
'keywords' => implode(',', $image->getTags()),
'description' => $image->getDescription(),
'caption' => $image->getTitle(),
'captionLong' => $image->getDescription(),
'parentAlbumId' => $this->albumId,
'mediaHandler' => 'extapp',
'thumbnailId' => null,
'previewId' => null,
'originalId' => null,
'thumbnailRef' => (string) $image->getSmallThumb(),
'thumbnailMimeType' => 'image/jpeg',
'thumbnailWidth' => 72,
'thumbnailHeight' => 0,
'thumbnailBytes' => 0,
'previewRef' => (string) $image->getMediumThumb(),
'previewMimeType' => 'image/jpeg',
'previewWidth' => 400,
'previewHeight' => 0,
'previewBytes' => 0,
'originalRef' => (string) $image->getContent(),
'originalMimeType' => 'image/jpeg',
'originalWidth' => 0,
'originalHeight' => 0,
'originalBytes' => 0,
'originalIsImage' => true,
'ownerName' => null);
mediashareAddKeywords($image);
return $image;
}
}
function mediashare_extapp_picasaapi_parseURL($args)
{
$r = '/picasaweb.google.com\/([-a-zA-Z0-9_.]+)\/([-a-zA-Z0-9_.]+)(\?authkey=([a-zA-Z0-9]+))?.*/';
if (preg_match($r, $args['url'], $matches)) {
return array('userName' => $matches[1], 'albumName' => $matches[2], 'authkey' => $matches[4]);
}
$r = '/picasaweb.google.com\/([-a-zA-Z0-9_.]+)\/?/';
if (preg_match($r, $args['url'], $matches)) {
return array('userName' => $matches[1], 'albumName' => null, 'authkey' => null);
}
return null;
}
function mediashare_extapp_picasaapi_getAlbumInstance($args)
{
return new MediasharePicasaAlbum($args['albumId'], $args['albumData']);
}