You are here

function _imagepicker_browse_public in Image Picker 5.2

Same name and namespace in other branches
  1. 6.2 imagepicker.functions.inc \_imagepicker_browse_public()
  2. 7 imagepicker.functions.inc \_imagepicker_browse_public()
3 calls to _imagepicker_browse_public()
imagepicker_admin_images in ./imagepicker.module
imagepicker_browse_public in ./imagepicker.module
imagepicker_user_browse_public in ./imagepicker.module

File

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

Code

function _imagepicker_browse_public($src = "iframe", $range = 1) {
  global $user;
  $how_many = variable_get('imagepicker_advanced_browser_page', 25);
  $default_order = variable_get('imagepicker_default_browser_order', 'img_id DESC');
  $order = $user->imagepicker_browser_order ? $user->imagepicker_browser_order : $default_order;
  if ($range == 1) {

    // Build sql for role restriction matching
    if (variable_get('imagepicker_publicroles_enabled', 1) && $src != 'admin') {
      $x = 1;
      foreach ($user->roles as $role) {
        if ($x == 1) {
          $rolesql = "AND (u.avail_roles = 'all' OR u.avail_roles LIKE '%%" . $role . "%%'";
        }
        else {
          $rolesql .= " OR u.avail_roles LIKE '%%" . $role . "%%'";
        }
        if ($x == count($user->roles)) {
          $rolesql .= ")";
        }
        $x++;
      }
    }
    $sql = "SELECT i.img_id, i.uid, i.img_name, i.img_title, i.img_description, i.img_date, n.name\n      FROM {imagepicker} i, {users} n, {imagepicker_user_groups} u, {imagepicker_group_images} g\n      WHERE i.uid = n.uid\n      AND u.public = 1\n      {$rolesql}\n      AND g.img_id = i.img_id\n      AND u.gid = g.gid\n      ORDER BY i.{$order}";
  }
  elseif ($range == 2) {
    $sql = "SELECT i.img_id, i.uid, i.img_name, i.img_title, i.img_description, i.img_date, n.name\n      FROM {imagepicker} i, {users} n, {imagepicker_user_groups} u, {imagepicker_group_images} g\n      WHERE i.uid = n.uid\n      AND u.public = 0\n      AND g.img_id = i.img_id\n      AND u.gid = g.gid\n      ORDER BY i.{$order}";
  }
  else {
    $sql = "SELECT DISTINCT i.img_id, i.uid, i.img_name, i.img_title, i.img_description, i.img_date, n.name\n      FROM {imagepicker} i, {users} n\n      WHERE i.uid = n.uid\n      ORDER BY i.{$order}";
  }
  $result = pager_query($sql, $how_many, 0, NULL);
  $content_main = _imagepicker_thumbs_display($result, TRUE, $src);
  if (empty($content_main)) {
    return '<div class="messages">' . t('There are no public images') . '</div>';
  }
  $content_head = "";
  if (variable_get('imagepicker_show_browse_order_form', 1)) {
    $content_head .= drupal_get_form('imagepicker_browse_order_form');
  }
  if ($src == 'admin') {
    $content_head .= drupal_get_form('imagepicker_browse_public_form');
  }
  if ($src == "account" || $src == 'admin') {
    $content_head .= '<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_head .= '<div class="imgp_help">' . t('Hold the mouse over an image to view Name, Title and Description, Click on it to use.') . '</div>';
  }
  $content = $content_head . $content_main;
  return $content;
}