You are here

function imagepicker_get_image_path in Image Picker 7

Same name and namespace in other branches
  1. 5.2 imagepicker.module \imagepicker_get_image_path()
  2. 5 imagepicker.module \imagepicker_get_image_path()
  3. 6.2 imagepicker.module \imagepicker_get_image_path()

Parameters

object or array $img:

string $type:

boolean $public:

Return value

string

11 calls to imagepicker_get_image_path()
imagepicker_adminview in ./imagepicker.admin.inc
imagepicker_admin_images in ./imagepicker.admin.inc
imagepicker_display_block in ./imagepicker.module
Function to display the contents of a block.
imagepicker_image_page in ./imagepicker.functions.inc
Menu callback; presents the image page for imagepicker
imagepicker_userview in ./imagepicker.user.inc

... See full list

File

./imagepicker.module, line 1027
@author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL

Code

function imagepicker_get_image_path($img, $type = 'browser', $public = FALSE, $preset = FALSE) {
  $userdir = is_array($public) ? $public : TRUE;
  $imgbasedir = imagepicker_get_path(FALSE, $userdir);
  $found = FALSE;
  $imgpath = '';

  // $img is object or array
  if (is_object($img)) {
    $img_name = $img->img_name;
  }
  else {
    $img_name = $img['img_name'];
  }
  $suffix = '';
  switch ($type) {
    case 'browser':
      if (file_exists($imgbasedir . IMAGEPICKER_BROWSER_DIR . DIRECTORY_SEPARATOR . $img_name)) {
        $suffix = IMAGEPICKER_BROWSER_DIR;
        $found = TRUE;
      }
      elseif (file_exists($imgbasedir . IMAGEPICKER_THUMBS_DIR . DIRECTORY_SEPARATOR . $img_name)) {
        $suffix = IMAGEPICKER_THUMBS_DIR;
        $found = TRUE;
      }
      break;
    case 'full':
      if (file_exists($imgbasedir . $img_name)) {
        $suffix = NULL;
        $found = TRUE;
      }
      break;
    case 'thumb':
    default:
      if (file_exists($imgbasedir . IMAGEPICKER_THUMBS_DIR . DIRECTORY_SEPARATOR . $img_name)) {
        $suffix = IMAGEPICKER_THUMBS_DIR;
        $found = TRUE;
      }
      elseif (file_exists($imgbasedir . IMAGEPICKER_BROWSER_DIR . DIRECTORY_SEPARATOR . $img_name)) {
        $suffix = IMAGEPICKER_BROWSER_DIR;
        $found = TRUE;
      }
      break;
    case 'watermarks':
      if (file_exists($imgbasedir . $img_name)) {
        $suffix = IMAGEPICKER_WATERMARK_DIR;
        $found = TRUE;
      }
      break;
    case 'orig':
      if (file_exists($imgbasedir . $img_name)) {
        $suffix = IMAGEPICKER_ORIG_DIR;
        $found = TRUE;
      }
      break;
  }
  if ($found) {
    if ($suffix) {
      if (imagepicker_variable_get('imagepicker_use_full_url', 0) || variable_get('file_default_scheme', 'public') == 'private') {
        if (module_exists('image') && imagepicker_variable_get('imagepicker_image_enable', 0) && $preset && $suffix == IMAGEPICKER_THUMBS_DIR) {
          $imgpath = image_style_url($preset, IMAGEPICKER_FILE_SCHEME . IMAGEPICKER_FILES_DIR . '/' . imagepicker_get_userpath($userdir) . $suffix . '/' . $img_name);
        }
        else {
          $imgpath = file_create_url(IMAGEPICKER_FILE_SCHEME . IMAGEPICKER_FILES_DIR . '/' . imagepicker_get_userpath($userdir) . $suffix . '/' . $img_name);
        }
      }
      else {
        if (module_exists('image') && imagepicker_variable_get('imagepicker_image_enable', 0) && $preset && $suffix == IMAGEPICKER_THUMBS_DIR) {
          $imgpath = image_style_url($preset, IMAGEPICKER_FILE_SCHEME . IMAGEPICKER_FILES_DIR . '/' . imagepicker_get_userpath($userdir) . $suffix . '/' . $img_name);
        }
        else {
          $imgpath = imagepicker_get_path(TRUE, $userdir) . $suffix . '/' . $img_name;
        }
      }
    }
    else {
      if (imagepicker_variable_get('imagepicker_use_full_url', 0) || variable_get('file_default_scheme', 'public') == 'private') {
        if (module_exists('image') && imagepicker_variable_get('imagepicker_image_enable', 0) && $preset) {
          $imgpath = image_style_url($preset, IMAGEPICKER_FILE_SCHEME . IMAGEPICKER_FILES_DIR . '/' . imagepicker_get_userpath($userdir) . $img_name);
        }
        else {
          $imgpath = file_create_url(IMAGEPICKER_FILE_SCHEME . IMAGEPICKER_FILES_DIR . '/' . imagepicker_get_userpath($userdir) . $img_name);
        }
      }
      else {
        if (module_exists('image') && imagepicker_variable_get('imagepicker_image_enable', 0) && $preset) {
          $imgpath = image_style_url($preset, IMAGEPICKER_FILE_SCHEME . IMAGEPICKER_FILES_DIR . '/' . imagepicker_get_userpath($userdir) . $img_name);
        }
        else {
          $imgpath = imagepicker_get_path(TRUE, $userdir) . $img_name;
        }
      }
    }
  }
  return $imgpath ? $imgpath : '';
}