You are here

function flickr_block_save in Flickr 7

Implements hook_block_save().

File

block/flickr_block.module, line 631
The Flickr block module

Code

function flickr_block_save($delta = '', $edit = array()) {
  switch ($delta) {

    // User recent Flickr photosets.
    case 1:
      variable_set('flickr_block_' . $delta, array(
        'show_n' => (int) $edit["flickr_block_{$delta}_show_n"],
        'size' => $edit["flickr_block_{$delta}_size"],
        'media' => $edit["flickr_block_{$delta}_media"],
        'min_title' => $edit["flickr_block_{$delta}_min_title"],
        'min_metadata' => $edit["flickr_block_{$delta}_min_metadata"],
      ));
      cache_clear_all('flickr_block_' . $delta, 'cache', TRUE);
      break;

    // User Flickr photos.
    case 0:
    case 2:
      $vocab = module_exists('taxonomy') ? (int) $edit["flickr_block_{$delta}_vocab"] : 0;
      $extend = module_exists('taxonomy') ? $edit["flickr_block_{$delta}_extend"] : 0;
      if (module_exists('taxonomy')) {
        $tag_mode = $extend ? 'any' : $edit["flickr_block_{$delta}_tag_mode"];
      }
      else {
        $tag_mode = 'context';
      }
      $geo = module_exists('geofield') || module_exists('location_node') ? $edit["flickr_block_{$delta}_geo"] : 0;
      $date = module_exists('date') ? $edit["flickr_block_{$delta}_date"] : 0;
      variable_set('flickr_block_' . $delta, array(
        'show_n' => (int) $edit["flickr_block_{$delta}_show_n"],
        'size' => $edit["flickr_block_{$delta}_size"],
        'sort' => $edit["flickr_block_{$delta}_sort"],
        'filter' => $edit["flickr_block_{$delta}_filter"],
        'media' => $edit["flickr_block_{$delta}_media"],
        'vocab' => $vocab,
        'extend' => $extend,
        'tag_mode' => $tag_mode,
        'geo' => $geo,
        'date' => $date,
        'min_title' => $edit["flickr_block_{$delta}_min_title"],
        'min_metadata' => $edit["flickr_block_{$delta}_min_metadata"],
      ));
      cache_clear_all('flickr_block_' . $delta, 'cache', TRUE);
      break;
    case 13:
    case 14:
    case 15:
    case 16:
      $vocab = module_exists('taxonomy') ? (int) $edit["flickr_block_{$delta}_vocab"] : 0;
      $extend = module_exists('taxonomy') ? $edit["flickr_block_{$delta}_extend"] : 0;
      if (module_exists('taxonomy')) {
        $tag_mode = $extend ? 'any' : $edit["flickr_block_{$delta}_tag_mode"];
      }
      else {
        $tag_mode = 'context';
      }
      variable_set('flickr_block_' . $delta, array(
        'show_n' => (int) $edit["flickr_block_{$delta}_show_n"],
        'size' => $edit["flickr_block_{$delta}_size"],
        'sort' => $edit["flickr_block_{$delta}_sort"],
        'media' => $edit["flickr_block_{$delta}_media"],
        'vocab' => $vocab,
        'extend' => $extend,
        'tag_mode' => $tag_mode,
        'min_title' => $edit["flickr_block_{$delta}_min_title"],
        'min_metadata' => $edit["flickr_block_{$delta}_min_metadata"],
      ));
      cache_clear_all('flickr_block_' . $delta, 'cache', TRUE);
      break;

    // Photos from a Flickr user.
    case 3:
    case 5:
      $userid = $edit["flickr_block_{$delta}_user_id"];
      if (!empty($userid) && $userid != 'public') {
        if (!flickr_is_nsid($edit["flickr_block_{$delta}_user_id"])) {
          if ($user = flickr_user_find_by_identifier($userid)) {
            drupal_set_message(t("The Flickr user associated with '%userid' has internally been replaced with the corresponding Flickr ID '%uid'.", array(
              '%userid' => $edit["flickr_block_{$delta}_user_id"],
              '%uid' => $user,
            )));
            $edit["flickr_block_{$delta}_user_id"] = $user;
          }
        }
        else {
          $info = flickr_people_getinfo($edit["flickr_block_{$delta}_user_id"]);
          drupal_set_message(t("The Flickr user associated with '%uid' will be shown to you as Flickr user '%userid'.", array(
            '%uid' => $edit["flickr_block_{$delta}_user_id"],
            '%userid' => $info['username']['_content'],
          )));
        }
      }
      $vocab = module_exists('taxonomy') ? (int) $edit["flickr_block_{$delta}_vocab"] : 0;
      $extend = module_exists('taxonomy') ? $edit["flickr_block_{$delta}_extend"] : 0;
      if (module_exists('taxonomy')) {
        $tag_mode = $extend ? 'any' : $edit["flickr_block_{$delta}_tag_mode"];
      }
      else {
        $tag_mode = 'context';
      }
      $geo = module_exists('geofield') || module_exists('location_node') ? $edit["flickr_block_{$delta}_geo"] : 0;
      $date = module_exists('date') ? $edit["flickr_block_{$delta}_date"] : 0;
      variable_set('flickr_block_' . $delta, array(
        'user_id' => $edit["flickr_block_{$delta}_user_id"],
        'show_n' => (int) $edit["flickr_block_{$delta}_show_n"],
        'size' => $edit["flickr_block_{$delta}_size"],
        'sort' => $edit["flickr_block_{$delta}_sort"],
        'filter' => $edit["flickr_block_{$delta}_filter"],
        'media' => $edit["flickr_block_{$delta}_media"],
        'vocab' => $vocab,
        'extend' => $extend,
        'tag_mode' => $tag_mode,
        'geo' => $geo,
        'date' => $date,
        'min_title' => $edit["flickr_block_{$delta}_min_title"],
        'min_metadata' => $edit["flickr_block_{$delta}_min_metadata"],
      ));
      $nsid = empty($edit["flickr_block_{$delta}_user_id"]) ? variable_get('flickr_default_userid', '') : $edit["flickr_block_{$delta}_user_id"];
      cache_clear_all('flickr_block_' . $delta, 'cache', TRUE);
      break;

    // Favorites from a Flickr user.
    case 9:
    case 12:
      $userid = $edit["flickr_block_{$delta}_user_id"];
      if (!empty($userid) && $userid != 'public') {
        if (!flickr_is_nsid($edit["flickr_block_{$delta}_user_id"])) {
          if ($user = flickr_user_find_by_identifier($userid)) {
            drupal_set_message(t("The Flickr user associated with '%userid' has internally been replaced with the corresponding Flickr ID '%uid'.", array(
              '%userid' => $edit["flickr_block_{$delta}_user_id"],
              '%uid' => $user,
            )));
            $edit["flickr_block_{$delta}_user_id"] = $user;
          }
        }
        else {
          $info = flickr_people_getinfo($edit["flickr_block_{$delta}_user_id"]);
          drupal_set_message(t("The Flickr user associated with '%uid' will be shown to you as Flickr user '%userid'.", array(
            '%uid' => $edit["flickr_block_{$delta}_user_id"],
            '%userid' => $info['username']['_content'],
          )));
        }
      }
      $vocab = module_exists('taxonomy') ? (int) $edit["flickr_block_{$delta}_vocab"] : 0;
      $extend = module_exists('taxonomy') ? $edit["flickr_block_{$delta}_extend"] : 0;
      if (module_exists('taxonomy')) {
        $tag_mode = $extend ? 'any' : $edit["flickr_block_{$delta}_tag_mode"];
      }
      else {
        $tag_mode = 'context';
      }
      variable_set('flickr_block_' . $delta, array(
        'user_id' => $edit["flickr_block_{$delta}_user_id"],
        'show_n' => (int) $edit["flickr_block_{$delta}_show_n"],
        'size' => $edit["flickr_block_{$delta}_size"],
        'sort' => $edit["flickr_block_{$delta}_sort"],
        'media' => $edit["flickr_block_{$delta}_media"],
        'vocab' => $vocab,
        'extend' => $extend,
        'tag_mode' => $tag_mode,
        'min_title' => $edit["flickr_block_{$delta}_min_title"],
        'min_metadata' => $edit["flickr_block_{$delta}_min_metadata"],
      ));
      $nsid = empty($edit["flickr_block_{$delta}_user_id"]) ? variable_get('flickr_default_userid', '') : $edit["flickr_block_{$delta}_user_id"];
      cache_clear_all('flickr_block_' . $delta, 'cache', TRUE);
      break;

    // Recent photosets from a Flickr user.
    case 4:
      $userid = $edit["flickr_block_{$delta}_user_id"];
      if (!empty($userid)) {
        if (!flickr_is_nsid($edit["flickr_block_{$delta}_user_id"])) {
          if ($user = flickr_user_find_by_identifier($userid)) {
            drupal_set_message(t("The Flickr user associated with '%userid' has internally been replaced with the corresponding Flickr ID '%uid'.", array(
              '%userid' => $edit["flickr_block_{$delta}_user_id"],
              '%uid' => $user,
            )));
            $edit["flickr_block_{$delta}_user_id"] = $user;
          }
        }
        else {
          $info = flickr_people_getinfo($edit["flickr_block_{$delta}_user_id"]);
          drupal_set_message(t("The Flickr user associated with '%uid' will be shown to you as Flickr user '%userid'.", array(
            '%uid' => $edit["flickr_block_{$delta}_user_id"],
            '%userid' => $info['username']['_content'],
          )));
        }
      }
      variable_set('flickr_block_' . $delta, array(
        'user_id' => $edit["flickr_block_{$delta}_user_id"],
        'show_n' => (int) $edit["flickr_block_{$delta}_show_n"],
        'size' => $edit["flickr_block_{$delta}_size"],
        'media' => $edit["flickr_block_{$delta}_media"],
        'min_title' => $edit["flickr_block_{$delta}_min_title"],
        'min_metadata' => $edit["flickr_block_{$delta}_min_metadata"],
      ));
      $nsid = empty($edit["flickr_block_{$delta}_user_id"]) ? variable_get('flickr_default_userid', '') : $edit["flickr_block_{$delta}_user_id"];
      cache_clear_all('flickr_block_' . $delta . '_' . $nsid, 'cache', TRUE);
      break;

    // Photos from a Flickr group.
    case 6:
    case 10:
      $vocab = module_exists('taxonomy') ? (int) $edit["flickr_block_{$delta}_vocab"] : 0;
      $extend = module_exists('taxonomy') ? $edit["flickr_block_{$delta}_extend"] : 0;
      if (module_exists('taxonomy')) {
        $tag_mode = $extend ? 'any' : $edit["flickr_block_{$delta}_tag_mode"];
      }
      else {
        $tag_mode = 'context';
      }
      $geo = module_exists('geofield') || module_exists('location_node') ? $edit["flickr_block_{$delta}_geo"] : 0;
      $date = module_exists('date') ? $edit["flickr_block_{$delta}_date"] : 0;
      variable_set('flickr_block_' . $delta, array(
        'group_id' => $edit["flickr_block_{$delta}_group_id"],
        'show_n' => (int) $edit["flickr_block_{$delta}_show_n"],
        'size' => $edit["flickr_block_{$delta}_size"],
        'sort' => $edit["flickr_block_{$delta}_sort"],
        'filter' => $edit["flickr_block_{$delta}_filter"],
        'media' => $edit["flickr_block_{$delta}_media"],
        'vocab' => $vocab,
        'extend' => $extend,
        'tag_mode' => $tag_mode,
        'geo' => $geo,
        'date' => $date,
        'min_title' => $edit["flickr_block_{$delta}_min_title"],
        'min_metadata' => $edit["flickr_block_{$delta}_min_metadata"],
      ));
      cache_clear_all('flickr_block_' . $delta . '_' . $edit["flickr_block_{$delta}_group_id"], 'cache', TRUE);
      break;

    // Photos from a Flickr photoset.
    case 7:
    case 8:
      $vocab = module_exists('taxonomy') ? (int) $edit["flickr_block_{$delta}_vocab"] : 0;
      $extend = module_exists('taxonomy') ? $edit["flickr_block_{$delta}_extend"] : 0;
      if (module_exists('taxonomy')) {
        $tag_mode = $extend ? 'any' : $edit["flickr_block_{$delta}_tag_mode"];
      }
      else {
        $tag_mode = 'context';
      }
      variable_set('flickr_block_' . $delta, array(
        'show_n' => (int) $edit["flickr_block_{$delta}_show_n"],
        'size' => $edit["flickr_block_{$delta}_size"],
        'sort' => $edit["flickr_block_{$delta}_sort"],
        'media' => $edit["flickr_block_{$delta}_media"],
        'photoset_id' => $edit["flickr_block_{$delta}_photoset"],
        'vocab' => $vocab,
        'extend' => $extend,
        'tag_mode' => $tag_mode,
        'min_title' => $edit["flickr_block_{$delta}_min_title"],
        'min_metadata' => $edit["flickr_block_{$delta}_min_metadata"],
      ));
      cache_clear_all('flickr_block_' . $delta . '_' . $edit["flickr_block_{$delta}_photoset"], 'cache', TRUE);
      break;

    // Random photos with a specific tag from a Flickr user.
    case 11:
      $userid = $edit["flickr_block_{$delta}_user_id"];
      $extend = module_exists('taxonomy') ? $edit["flickr_block_{$delta}_extend"] : 0;
      if (module_exists('taxonomy')) {
        $tag_mode = $extend ? 'any' : $edit["flickr_block_{$delta}_tag_mode"];
      }
      if (!empty($userid) && $userid != 'public') {
        if (!flickr_is_nsid($edit["flickr_block_{$delta}_user_id"])) {
          if ($user = flickr_user_find_by_identifier($userid)) {
            drupal_set_message(t("The Flickr user associated with '%userid' has internally been replaced with the corresponding Flickr ID '%uid'.", array(
              '%userid' => $edit["flickr_block_{$delta}_user_id"],
              '%uid' => $user,
            )));
            $edit["flickr_block_{$delta}_user_id"] = $user;
          }
        }
        else {
          $info = flickr_people_getinfo($edit["flickr_block_{$delta}_user_id"]);
          drupal_set_message(t("The Flickr user associated with '%uid' will be shown to you as Flickr user '%userid'.", array(
            '%uid' => $edit["flickr_block_{$delta}_user_id"],
            '%userid' => $info['username']['_content'],
          )));
        }
      }
      variable_set('flickr_block_' . $delta, array(
        'user_id' => $edit["flickr_block_{$delta}_user_id"],
        // Remove whitespace from the tag list.
        'tag' => preg_replace('/\\s+/', '', $edit["flickr_block_{$delta}_tag"]),
        'show_n' => (int) $edit["flickr_block_{$delta}_show_n"],
        'size' => $edit["flickr_block_{$delta}_size"],
        'sort' => $edit["flickr_block_{$delta}_sort"],
        'filter' => $edit["flickr_block_{$delta}_filter"],
        'media' => $edit["flickr_block_{$delta}_media"],
        'extend' => $extend,
        'tag_mode' => $tag_mode,
        'min_title' => $edit["flickr_block_{$delta}_min_title"],
        'min_metadata' => $edit["flickr_block_{$delta}_min_metadata"],
      ));
      $nsid = empty($edit["flickr_block_{$delta}_user_id"]) ? variable_get('flickr_default_userid', '') : $edit["flickr_block_{$delta}_user_id"];
      cache_clear_all('flickr_block_' . $delta, 'cache', TRUE);
      break;
  }
}