You are here

function _imagepicker_browse in Image Picker 5

Same name and namespace in other branches
  1. 5.2 imagepicker.module \_imagepicker_browse()
  2. 6.2 imagepicker.functions.inc \_imagepicker_browse()
  3. 7 imagepicker.functions.inc \_imagepicker_browse()
2 calls to _imagepicker_browse()
imagepicker_browse in ./imagepicker.module
imagepicker_user_browse in ./imagepicker.module

File

./imagepicker.module, line 1339
Enables permitted roles to upload images for insertion into configured nodes.

Code

function _imagepicker_browse($src = "iframe") {
  global $user;
  $content = "";

  // paths
  if ($src == 'iframe') {
    $imgurl = 'imagepicker/browse/';
  }
  else {
    $imgurl = 'user/' . $user->uid . '/imagepicker/browse/';
  }
  if (variable_get('imagepicker_show_browse_order_form', 1)) {
    $content .= drupal_get_form('imagepicker_browse_order_form');
  }
  if (imagepicker_get_groups() && imagepicker_has_grouplist()) {

    // add groups select here
    $content .= drupal_get_form('imagepicker_browse_groups_form');
  }
  if ($src == "account") {
    $content .= '<div class="imgp_help">' . t('Hold the mouse over an image to view Name, Title and Description, Click on it to view.') . '</div>';
  }
  else {
    $content .= '<div class="imgp_help">' . t('Hold the mouse over an image to view Name, Title and Description, Click on it to use.') . '</div>';
  }
  $content .= '<div class="clear-block">';

  // if there are groups
  $gid = 0;
  if (imagepicker_get_groups()) {
    $gids = imagepicker_get_user_group_state();
    $gid = $gids[0];
  }
  $how_many = variable_get('imagepicker_advanced_browser_page', 25);
  $default_order = variable_get('imagepicker_default_browser_order', 'img_id DESC');
  $order = variable_get('imagepicker_browser_order', $default_order);

  // filter by selected group
  if ($gid) {
    $sql = "SELECT i.img_id, i.uid, i.img_name, i.img_title, i.img_description, i.img_date\n      FROM {imagepicker} i, {imagepicker_group_images} g\n      WHERE i.uid = %d AND i.img_id = g.img_id AND g.gid = %d\n      ORDER BY i.{$order}";
    $result = pager_query($sql, $how_many, 0, NULL, array(
      $user->uid,
      $gid,
    ));
  }
  else {
    $sql = "SELECT * FROM {imagepicker} WHERE uid=%d ORDER BY {$order}";
    $result = pager_query($sql, $how_many, 0, NULL, array(
      $user->uid,
    ));
  }
  $browsercols = variable_get('imagepicker_advanced_browser_columns', 0);
  $ct = 0;
  $imgct = 0;
  while ($img = db_fetch_array($result)) {

    // img_id img_name 	img_title 	img_description
    $imgpath = imagepicker_get_image_path($img, 'browser');
    if ($imgpath) {
      $tooltip = $img['img_name'] . ': ' . $img['img_title'] . ' ' . $img['img_description'];
      $imglink = '<img src="' . $imgpath . '" alt="' . $img['img_title'] . '" title="' . $tooltip . '" />';
      $content .= '<div class="imgp_holder">';
      $content .= l($imglink, $imgurl . $img['img_id'], array(), NULL, NULL, FALSE, TRUE);
      $content .= '</div>';
      $ct++;
      if ($browsercols > 0 && $ct >= $browsercols) {
        $content .= '</div><div class="clear-block">';
        $ct = 0;
      }
    }
    $imgct++;
  }
  $content .= '</div>';
  $content .= theme('pager', NULL, $how_many);
  if (!$imgct) {
    $content = '<div class="messages">' . t('You do not have any uploaded images') . '</div>';
  }
  return $content;
}