t('Flickr linker'), 'description' => t('Allows you to Insert Flickr images: [flickr-photo:id=230452326,size=s] or [flickr-photoset:id=72157594262419167,size=m]'), 'process callback' => '_filter_flickr', 'tips callback' => '_filter_flickr_tips', ); return $filters; } /** * Returns the filter information for the filter help page */ function _filter_flickr_tips($filter, $format, $long = FALSE) { $output = t('Insert Flickr images: [flickr-photo:id=230452326,size=s] or [flickr-photoset:id=72157594262419167,size=m].'); if ($long) { $output .= ' ' . t('The size parameter can be one of the following:'); $items = array(); foreach (flickr_photo_sizes() as $key => $text) { $items[] = "$key — (" . $text['label'] . ') ' . $text['description']; } $output .= theme('item_list', array('items' => $items)); } return $output; } /** * Processes the flickr filter */ function _filter_flickr($text, $filter) { $text = preg_replace_callback('/\[flickr-photo:(.+?)\]/', 'flickr_filter_callback_photo', $text); $text = preg_replace_callback('/\[flickr-photoset:(.+?)\]/', 'flickr_filter_callback_photoset', $text); return $text; } /** * 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', array('photo' => $photo, 'size' => $config['size'], 'attribs' => $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', array('photoset' => $photoset, 'owner' => $photoset['owner'], 'size' => $config['size'], 'attribs' => $attribs)); } } return ''; } /** * Implements hook_theme(). */ function flickr_filter_theme() { return array( 'flickr_filter_photo' => array( 'variables' => array('photo', 'size', 'attribs'), ), 'flickr_filter_photoset' => array( 'variables' => array('photoset', 'owner', 'size', 'attribs'), ), ); } function theme_flickr_filter_photo($variables) { return theme('flickr_photo', $variables); } function theme_flickr_filter_photoset($variables) { return theme('flickr_photoset', $variables); }