$text) {
$items[] = "$key
— (". $text['label'] .') '. $text['description'];
}
$output .= theme('item_list', $items);
}
return $output;
}
}
function flickr_filter($op, $delta = 0, $format = -1, $text = '') {
if ($op == 'list') {
return array(0 => t('Flickr linker'));
}
switch ($delta) {
case 0:
switch ($op) {
case 'description':
return t('Insert photos or photosets from Flickr without tags: [flickr-photo:id=230452326]');
case 'no cache':
// TODO: only return true when testing the filter
// return TRUE;
return FALSE;
case 'prepare':
return $text;
case 'process':
$text = preg_replace_callback('/\[flickr-photo:(.+?)\]/', 'flickr_filter_callback_photo', $text);
$text = preg_replace_callback('/\[flickr-photoset:(.+?)\]/', 'flickr_filter_callback_photoset', $text);
return $text;
}
break;
}
}
/**
* Parse parameters to the fiter from a format like:
* id=26159919@N00, size=m,show = 9, class=something,style=float:left;border:1px
* into an associative array with two sub-arrays. The first sub-array is
* parameters for the request, the second are HTML attributes (class and style).
*/
function flickr_filter_split_config($string) {
$config = array();
$attribs = array();
// put each setting on its own line
$string = str_replace(',', "\n", $string);
// break them up around commas
preg_match_all('/([a-zA-Z]+)=([-@0-9a-zA-Z:;]+)/', $string, $parts, PREG_SET_ORDER);
foreach ($parts as $part) {
// normalize to lower case and remove extra spaces
$name = strtolower(trim($part[1]));
$value = trim($part[2]);
if ($name == 'style' || $name == 'class') {
$attribs[$name] = $value;
}
else {
$config[$name] = $value;
}
}
return array($config, $attribs);
}
/**
* Filter callback for a photo.
*/
function flickr_filter_callback_photo($matches) {
list($config, $attribs) = flickr_filter_split_config($matches[1]);
if (isset($config['id'])) {
if ($photo = flickr_photo_get_info($config['id'])) {
return theme('flickr_filter_photo', $photo, $config['size'], $attribs);
}
}
return '';
}
/**
* Filter callback for a photoset.
*/
function flickr_filter_callback_photoset($matches) {
list($config, $attribs) = flickr_filter_split_config($matches[1]);
if (isset($config['id'])) {
if ($photoset = flickr_photoset_get_info($config['id'])) {
return theme('flickr_filter_photoset', $photoset, $photoset['owner'], $config['size'], $attribs);
}
}
return '';
}
function theme_flickr_filter_photo($p, $size, $attribs) {
return theme('flickr_photo',$p, $size, NULL, $attribs);
}
function theme_flickr_filter_photoset($ps, $owner, $size, $attribs) {
return theme('flickr_photoset',$ps, $owner, $size, $attribs);
}