#picasa(): {$params['_error']}
\n";
} elseif($photoid =='') {
return "" . $params['album']['_body'] . "
\n";
} elseif(isset($params['photos'][$photoid])) {
return "" . $params['photos'][$photoid]['_body'] . "
\n";
} else {
return "#picasa(): photoid: " . htmlspecialchars($photoid) . " is not found.
\n";
}
}
function plugin_picasa_action() {
global $vars;
$userid = isset($vars['userid']) ? $vars['userid'] : '';
$albumid = isset($vars['albumid']) ? $vars['albumid'] : '';
$photoid = isset($vars['photoid']) ? $vars['photoid'] : '';
$params = picasa_get_album($userid, $albumid);
if (isset($params['_error']) && $params['_error'] != '') {
return array(
'result' => FALSE,
'msg' => $params['_error']);
} else {
$msg = 'picasa';
if($photoid =='') {
return array(
'msg' => $msg,
'body' => "" . $params['album']['_body'] . "
\n");
} else {
if(isset($params['photos'][$photoid])) {
return array(
'msg' => $msg,
'body' => "" . $params['photos'][$photoid]['_body'] . "
\n");
} else {
return array(
'result' => FALSE,
'msg' => "photoid: $photoid is not found.");
}
}
}
}
function picasa_get_album($userid, $albumid) {
global $date_format, $time_format, $weeklabels;
$data = picasa_get_album_xml($userid, $albumid);
if($data) {
$data = mb_convert_encoding($data, SOURCE_ENCODING, 'UTF-8');
$album = array();
$photos = array();
$album['albumid'] = $albumid;
$album['link'] = preg_match("/]*>([^<]*)<\/link>/s", $data, $match) ? $match[1] : '';
$album['date'] = preg_match("/]*>([^<]*)<\/lastBuildDate>/s", $data, $match) ? $match[1] : '';
$album['title'] = preg_match("/]*>([^<]*)<\/title>/s", $data, $match) ? $match[1] : '';
$album['description'] = preg_match("/]*>([^<]*)<\/description>/s", $data, $match) ? $match[1] : '';
$album['editor'] = preg_match("/]*>([^<]*)<\/managingEditor>/s", $data, $match) ? $match[1] : '';
$album['_body'] = '';
preg_match_all("/- ((?:(?!
- /s", $data, $items, PREG_SET_ORDER);
foreach($items as $item) {
if(preg_match("/([^<]*)<\/link>/s", $item[1], $match) ? $match[1] : '';
$photo['date'] = preg_match("/]*>([^<]*)<\/pubDate>/s", $item[1], $match) ? strtotime($match[1]) : '';
$photo['title'] = preg_match("/]*>([^<]*)<\/media:title>/s", $item[1], $match) ? $match[1] : '';
$photo['html'] = preg_match("/]*>([^<]*)<\/description>/s", $item[1], $match) ? $match[1] : '';
$photo['credit'] = preg_match("/]*>([^<]*)<\/media:credit>/s", $item[1], $match) ? $match[1] : '';
$photo['description'] = preg_match("/]*>([^<]*)<\/media:description>/s", $item[1], $match) ? $match[1] : '';
if(preg_match("/";
// $photodate = $photo['date'] + LOCALZONE;
$photodate = $photo['date'];
$table = "" . str_replace("\n", "
", htmlspecialchars($photo['description'])) . '
' .
"Date: " . date($date_format, $photodate) . ' (' . $weeklabels[date('w', $photodate)] . ') ' . date($time_format, $photodate) . "
" .
"Album: " . htmlspecialchars($album['title']) . '
' .
"Filename: " . htmlspecialchars($photo['title']) . '
';
$photo['_body'] = <<
{$photo['_image']} |
$table |
EOD;
$photos[$pid] = $photo;
$album['_body'] .= $photo['_body'];
}
}
return array('album' => $album, 'photos' => $photos);
} else {
return array('_error' => 'Album not found.');
}
}
function picasa_get_album_xml($userid, $albumid) {
global $vars;
$file = PICASA_CACHE_DIR . $userid . '.' . $albumid . '.xml';
$cachedate = file_exists($file) ? filemtime($file) - LOCALZONE : 0;
$pagedate = get_filetime($vars['page']);
if(($pagedate > $cachedate) or ($pagedate == 0) or ($cachedate == 0) or ! file_exists($file)) {
$req = http_request("http://picasaweb.google.co.jp/data/feed/base/user/$userid/albumid/$albumid?category=photo&alt=rss");
if ($req['rc'] == 200) {
$data = $req["data"];
$fp = fopen($file, "wb");
@flock($fp, LOCK_EX);
$last = ignore_user_abort(1);
ftruncate($fp, 0);
fwrite($fp, $data);
fflush($fp);
ignore_user_abort($last);
@flock($fp, LOCK_UN);
fclose($fp);
return $data;
} else {
return false;
}
} else {
$data = '';
$fp = @fopen($file, 'rb');
flock($fp, LOCK_SH);
do {
$tmp = fread($fp, 8192);
$data .= $tmp;
} while (strlen($tmp) != 0);
flock($fp, LOCK_UN);
@fclose($fp);
return $data;
}
}
?>