You are here

flickr_filter.module in Flickr 6

Same filename and directory in other branches
  1. 5 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';

/**
 * Implements hook_help().
 */
function flickr_filter_help($path, $arg) {
  switch ($path) {
    case 'admin/help#flickr_filter':

      // Return a line-break version of the README.txt.
      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> &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('Allows you to Insert Flickr images: [flickr-photo:id=230452326,size=s] or [flickr-photoset:id=72157594262419167,size=m]');
        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 filter 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'])) {
      if (!isset($config['size'])) {
        $config['size'] = variable_get('flickr_default_size', 'm');
      }
      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'])) {
      if (!isset($config['size'])) {
        $config['size'] = variable_get('flickr_default_size', 'm');
      }
      return theme('flickr_filter_photoset', $photoset, $photoset['owner'], $config['size'], $attribs);
    }
  }
  return '';
}

/**
 * Implements hook_theme().
 */
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);
}

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_help Implements hook_help().
flickr_filter_split_config Parse parameters to the filter 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_theme Implements hook_theme().
flickr_filter_tips
theme_flickr_filter_photo
theme_flickr_filter_photoset