You are here

flickr_filter.module in Flickr 5

Same filename and directory in other branches
  1. 6 filter/flickr_filter.module
  2. 7 filter/flickr_filter.module

File

filter/flickr_filter.module
View source
<?php

require_once drupal_get_path('module', 'flickr') . '/flickr.inc';
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> &mdash; (" . $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 <img> 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);
}

Functions

Namesort descending Description
flickr_filter
flickr_filter_callback_photo Filter callback for a photo.
flickr_filter_callback_photoset Filter callback for a photoset.
flickr_filter_split_config 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…
flickr_filter_tips
theme_flickr_filter_photo
theme_flickr_filter_photoset