View source
<?php
require_once drupal_get_path('module', 'flickr') . '/flickr.inc';
function flickr_filter_help($path, $arg) {
switch ($path) {
case 'admin/help#flickr_filter':
return _filter_autop(file_get_contents(dirname(__FILE__) . '/README.txt'));
}
}
function flickr_filter_tips($delta, $format, $long = FALSE) {
switch ($delta) {
case 0:
$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[] = "<code>{$key}</code> — (" . $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('Allows you to Insert Flickr images: [flickr-photo:id=230452326,size=s] or [flickr-photoset:id=72157594262419167,size=m]');
case 'no cache':
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;
}
}
function flickr_filter_split_config($string) {
$config = array();
$attribs = array();
$string = str_replace(',', "\n", $string);
preg_match_all('/([a-zA-Z]+)=([-@0-9a-zA-Z:;]+)/', $string, $parts, PREG_SET_ORDER);
foreach ($parts as $part) {
$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,
);
}
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'])) {
if (!isset($config['size'])) {
$config['size'] = variable_get('flickr_default_size', 'm');
}
return theme('flickr_filter_photo', $photo, $config['size'], $attribs);
}
}
return '';
}
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'])) {
if (!isset($config['size'])) {
$config['size'] = variable_get('flickr_default_size', 'm');
}
return theme('flickr_filter_photoset', $photoset, $photoset['owner'], $config['size'], $attribs);
}
}
return '';
}
function flickr_filter_theme() {
return array(
'flickr_filter_photo' => array(
'arguments' => array(
'p',
'size',
'attribs',
),
),
'flickr_filter_photoset' => array(
'arguments' => array(
'ps',
'owner',
'size',
'attribs',
),
),
);
}
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);
}