This repository has been archived by the owner on Aug 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpnextapp_smugmugapi.php
109 lines (96 loc) · 3.41 KB
/
pnextapp_smugmugapi.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
<?php
// $Id$
//
// Mediashare by Jorn Lind-Nielsen (C)
//
require_once 'modules/mediashare/common.php';
require_once 'modules/mediashare/pnincludes/phpSmug/phpSmug.php';
class MediashareSmugMugAlbum extends MediashareBaseAlbum
{
var $smugApi;
function MediashareSmugMugAlbum($albumId, $albumData)
{
$albumData['allowMediaEdit'] = false;
$this->albumId = $albumId;
$this->albumData = $albumData;
}
function getApi()
{
if ($this->smugApi == null) {
$APIKey = pnModGetVar('mediashare', 'smugmugAPIKey');
$this->smugApi = new phpSmug(array('APIKey' => $APIKey));
$this->smugApi->login();
}
return $this->smugApi;
}
function getMediaItems()
{
if (($images = $this->getRawImages()) === false) {
return array();
}
for ($i = 0, $cou = count($images); $i < $cou; ++$i) {
$images[$i] = $this->convertImage($images[$i]);
}
$this->fixMainMedia($images);
return $images;
}
function getRawImages()
{
$data = $this->albumData['extappData']['data'];
$images = $this->getApi()->images_get(array('AlbumID' => $data['albumId'], 'AlbumKey' => $data['albumKey'], 'Heavy' => true));
return $images;
}
function convertImage($image)
{
return array(
'id' => $image['id'],
'ownerId' => null,
'createdDate' => $image['LastUpdated'],
'modifiedDate' => $image['LastUpdated'],
'title' => empty($image['Caption']) ? $image['Key'] : $image['Caption'],
'keywordsArray' => array(),
'hasKeywords' => false,
'keywords' => $image['Keywords'],
'description' => '',
'caption' => $image['Caption'],
'captionLong' => $image['Caption'],
'parentAlbumId' => $this->albumId,
'mediaHandler' => 'extapp',
'thumbnailId' => null,
'previewId' => null,
'originalId' => null,
'thumbnailRef' => $image['TinyURL'],
'thumbnailMimeType' => 'image/jpeg',
'thumbnailWidth' => 0,
'thumbnailHeight' => 0,
'thumbnailBytes' => 0,
'previewRef' => $image['SmallURL'],
'previewMimeType' => 'image/jpeg',
'previewWidth' => 400,
'previewHeight' => 0,
'previewBytes' => 0,
'originalRef' => $image['LargeURL'],
'originalMimeType' => 'image/jpeg',
'originalWidth' => $image['Width'],
'originalHeight' => $image['Height'],
'originalBytes' => 0,
'originalIsImage' => true,
'ownerName' => null);
}
}
function mediashare_extapp_smugmugapi_parseURL($args)
{
// User: http://bilroy.smugmug.com/
// Gallery: http://bilroy.smugmug.com/gallery/5146474_BLeSn#316967890_QjBHz
// Popular: http://bilroy.smugmug.com/popular/#312830908_gzKhz
// Keyword: http://bilroy.smugmug.com/keyword/architecture#312830908_gzKhz
$r = '/smugmug\.com\/gallery\/([-a-zA-Z0-9_]+)_([-a-zA-Z0-9_]+)/';
if (preg_match($r, $args['url'], $matches)) {
return array('albumId' => $matches[1], 'albumKey' => $matches[2], 'userName' => null);
}
return null;
}
function mediashare_extapp_smugmugapi_getAlbumInstance($args)
{
return new MediashareSmugMugAlbum($args['albumId'], $args['albumData']);
}