View source
<?php
define('EMIMAGE_PICASA_MAIN_URL', 'http://picasaweb.google.com/');
define('EMIMAGE_PICASA_API_INFO', 'http://code.google.com/apis/picasaweb/developers_guide_protocol.html');
define('EMIMAGE_PICASA_REST_ENDPOINT', 'http://picasaweb.google.com/data/feed/api/user/');
define('EMIMAGE_PICASA_DATA_VERSION', 1);
function emimage_picasa_info() {
$features = array(
array(
t('Import photosets'),
t('No'),
'',
),
);
return array(
'provider' => 'picasa',
'name' => t('Picasa'),
'url' => EMIMAGE_PICASA_MAIN_URL,
'settings_description' => t('These settings specifically affect images displayed from <a href="@picasa" target="_blank">Picasa</a>.', array(
'@picasa' => EMIMAGE_PICASA_MAIN_URL,
)),
'supported_features' => $features,
'import_sets_word' => t('photosets'),
);
}
function emimage_picasa_request($data = array(), $kind = '', $cached = TRUE) {
$args['kind'] = $kind;
$xml = module_invoke('emfield', 'request_xml', 'picasa', EMIMAGE_PICASA_REST_ENDPOINT . "{$data['userid']}/album/{$data['album']}/photoid/{$data['photoid']}", $args, $cached, FALSE, ":{$data['userid']}:{$data['album']}?{$data['photoid']}");
return $xml;
}
function emimage_picasa_data_version() {
return EMIMAGE_PICASA_DATA_VERSION;
}
function emimage_picasa_data($field, $item) {
$data = array();
if (preg_match('@picasaweb\\.google\\.com/([^/]+)/([^/]+)/photo.*?#(.*)@i', $item['embed'], $matches)) {
$data = array(
'userid' => $matches[1],
'album' => $matches[2],
'photoid' => $matches[3],
);
}
elseif (preg_match('@picasaweb\\.google\\.com/([^/]+)/([^/\\?]+).*?#([^\\&]+)@i', $item['embed'], $matches)) {
$data = array(
'userid' => $matches[1],
'album' => $matches[2],
'photoid' => $matches[3],
);
}
$xml = emimage_picasa_request($data, 'tag');
$data['title'] = $xml['MEDIA:GROUP']['MEDIA:DESCRIPTION'][0];
$data['original'] = $xml['MEDIA:GROUP']['MEDIA:CONTENT'][1][URL];
$data['small'] = $xml['MEDIA:GROUP']['MEDIA:THUMBNAIL'][1][URL];
$data['medium'] = $xml['MEDIA:GROUP']['MEDIA:THUMBNAIL'][3][URL];
$data['large'] = $xml['MEDIA:GROUP']['MEDIA:THUMBNAIL'][5][URL];
$data['width'] = $xml['MEDIA:GROUP']['MEDIA:THUMBNAIL'][5][WIDTH];
$data['height'] = $xml['MEDIA:GROUP']['MEDIA:THUMBNAIL'][5][HEIGHT];
$data['emimage_data_version'] = EMIMAGE_PICASA_DATA_VERSION;
return $data;
}
function emimage_picasa_validate($value, $error_field) {
if ($value == 'PICASA_ERROR_USER') {
form_set_error($error_field, t("This URL does not contain enough information to access Picasa's current API. Please find the photo through this user's gallery and link its URL here."));
}
}
function emimage_picasa_extract($embed = '') {
if (preg_match('@picasaweb\\.google\\.com/lh/(.+)@i', $embed, $matches)) {
return 'PICASA_ERROR_USER';
}
return array(
'@picasaweb\\.google\\.com/[^/]+/[^/]+/photo.*?#([^\\&]+)@i',
'@picasaweb\\.google\\.com/[^/]+/[^/\\?]+.*?#([^\\&]+)@i',
);
}
function emimage_picasa_embedded_link($code, $data) {
$userid = $data['userid'];
$album = $data['album'];
$photoid = $data['photoid'];
return "http://picasaweb.google.com/{$userid}/{$album}/photo#{$photoid}";
}
function emimage_picasa_image_url($code, $width, $height, $formatter, $field, $item, $node) {
if (func_num_args() == 7) {
$arg = func_get_arg(5);
$code =& $arg['data']['original'];
$data =& $arg['data'];
$size = _emimage_picasa_guess_size($width, $height);
}
if (preg_match('!([^/]*)\\.ggpht\\.com/([^/]*)/([^/]*)/([^/]*)/([^/]*)/(.*)!i', $code, $matches)) {
$info = array(
'server' => $matches[1],
'userid' => $matches[2],
's1' => $matches[3],
's2' => $matches[4],
's3' => $matches[5],
'image' => $matches[6],
);
}
return "http://{$info['server']}.google.com/{$info['userid']}/{$info['s1']}/{$info['s2']}/{$info['s3']}/s{$size}/{$info['image']}";
}
function emimage_picasa_image_title($code, $data) {
if (func_num_args() == 7) {
$arg = func_get_arg(5);
$code =& $arg['data']['title'];
$data =& $arg['data'];
$title = $code;
}
return "{$title}";
}
function _emimage_picasa_guess_size($width, $height) {
$max = max($width, $height);
foreach (array(
'144' => 144,
'288' => 288,
'400' => 400,
'800' => 800,
) as $size => $value) {
if ($max <= $value) {
return $size;
}
}
return '800';
}
function emimage_picasa_thumbnail($field, $item, $formatter, $node, $width, $height) {
return emimage_picasa_image_url($item['value'], $width, $height, $formatter, $field, $item, $node);
}