You are here

function imce_browse in IMCE 5

Image Browser.

1 string reference to 'imce_browse'
imce_menu in ./imce.module
Implementation of hook_menu().

File

./imce.module, line 115

Code

function imce_browse() {
  $set = (object) imce_settings_user();
  $private = variable_get('file_downloads', '') == FILE_DOWNLOADS_PRIVATE;
  $syspath = file_directory_path();
  $basepath = base_path();
  $imcepath = $basepath . drupal_get_path('module', 'imce');
  $header = array(
    array(
      'data' => t('filename'),
      'class' => 'filename',
    ),
    array(
      'data' => t('size'),
      'class' => 'size',
    ),
    array(
      'data' => t('dimensions'),
      'class' => 'dimensions',
    ),
    array(
      'data' => t('date'),
      'class' => 'date',
    ),
    array(
      'data' => t('operations'),
      'class' => 'operations',
    ),
  );
  $token = drupal_get_token('imce');

  //file list
  $directory = imce_scan_directory($set->dir);

  //prevent quota theft by multiple sessions.
  if ($_SESSION['imcelatest'] && $directory['size'] > $set->quota * 1024 && !$set->nolimit) {
    $directory['size'] -= filesize($_SESSION['imcelatest']);
    @unlink($_SESSION['imcelatest']);
    unset($directory['files'][$_SESSION['imcelatest']], $_SESSION['imcelatest']);
    drupal_set_message(t('File was deleted due to quota exceed!'), 'error');
  }
  foreach ($directory['files'] as $path => $file) {
    $rows[] = array(
      array(
        'data' => $file['f'],
        'class' => 'filename',
      ),
      array(
        'data' => format_size($file['s']),
        'class' => 'size',
        'id' => 's-' . $file['s'],
      ),
      array(
        'data' => $file['w'] . 'x' . $file['h'],
        'class' => 'dimensions',
      ),
      array(
        'data' => date('Y-m-d', $file['d']),
        'class' => 'date',
        'id' => 'd-' . $file['d'],
        'title' => date('H:i:s', $file['d']),
      ),
      array(
        'data' => $set->delete ? l(t('delete'), 'imce/delete/' . $file['f'], NULL, 'token=' . $token) : '',
        'class' => 'operations',
      ),
    );
  }
  if (!isset($rows)) {
    $rows = array(
      array(
        '<div class="messages">' . t('Directory is empty.') . '</div>',
      ),
    );
  }
  $_SESSION['imcetotal'] = $directory['size'];

  //folder list
  if ($set->subnav) {
    foreach ($directory['folders'] as $folder) {
      $foptions .= '<option value="' . $folder . '">/' . $folder . '</option>';
    }
    $subdir = $set->root != $set->dir;
    if ($foptions || $subdir) {
      $foptions = ' <form action="' . url('imce/dir') . '" name="dirform" id="dirform" method="post"><select name="dirname" id="dirname">' . ($subdir ? '<option value="..">' . t('Up') . '</option>' : '') . '<option value="/" selected="selected">/</option>' . $foptions . '</select><input type="submit" name="op" id="dirop" value="' . t('Go') . '" /><input type="hidden" name="token" value="' . $token . '" /></form>';
    }
  }

  //upload form
  if ($set->upload) {
    $uploadform = '<form action="' . url('imce/upload') . '" method="post" id="uploadform" enctype="multipart/form-data">
  <input type="file" name="thefile" id="thefile" size="30" />
  <input type="hidden" name="token" value="' . $token . '" />
  <input type="submit" name="submit" value="' . t('Upload File') . '" />' . ($set->nolimit ? '<input type="checkbox" checked="checked" name="scale" />' . t('Scale if necessary') : ($set->scale ? '<input type="hidden" value="1" name="scale" />' : '')) . ($set->twidth && $set->theight ? '<input type="checkbox" name="thumb" />' . t('Create thumbnail') . ' (' . $set->twidth . 'x' . $set->theight . ')' : '') . '
</form>
<div class="limits">' . ($set->nolimit ? t('Dimensions for scaling') . ' = <strong>' . $set->width . 'x' . $set->height . '</strong>, ' . t('Quota') . ' = <strong>' . format_size($_SESSION['imcetotal']) . '</strong>/' . t('Unlimited') : '<strong>' . t('Limits') . '</strong>: ' . t('File size') . ' = <strong>' . $set->filesize . ' KB</strong>, ' . t('Dimensions') . ' = <strong>' . $set->width . 'x' . $set->height . '</strong>, ' . t('Quota') . ' = <strong>' . format_size($_SESSION['imcetotal']) . '</strong>/' . $set->quota . ' KB') . '</div>';
  }

  //resize form
  if ($set->resize) {
    $resizeform = '<form action="' . url('imce/resize') . '" method="post" id="resizeform">
  <input type="submit" name="submit" value="' . t('Resize image') . '" />
  <input type="hidden" name="token" value="' . $token . '" />
  <span id="resize-file-span">' . t('filename') . ':<input type="text" name="img_name" id="img_name" size="12" />
  ' . t('dimensions') . ':</span><input type="text" name="img_w" id="img_w" size="2" />x<input type="text" name="img_h" id="img_h" size="2" />
  <input type="checkbox" name="img_copy" />' . t('Create a copy') . '
</form>';
  }
  $output = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>' . t('Image/File Browser') . '</title>
  <script type="text/javascript">
    var imceVar = [];
    imceVar["fileUrl"] = "' . imce_relative_url($set->dir) . '";
    imceVar["latestFile"] = "' . ($_SESSION['imcelatest'] ? imce_relative_url($_SESSION['imcelatest']) : '') . '";
    imceVar["confirmDel"] = "' . ($set->delete ? t('Are you sure want to delete this file?') : '') . '";
    imceVar["viewText"] = "' . t('view') . '";
    imceVar["addText"] = "' . t('add') . '";' . ($set->extras ? '
    imceVar["filterText"] = ["' . t('Display') . '", "' . t('all') . '", "' . t('images') . '", "' . t('non-images') . '"];' : '') . '
  </script>
  <script type="text/javascript" src="' . $basepath . 'misc/jquery.js"></script>
  <script type="text/javascript" src="' . $imcepath . '/imce_browse.js"></script>' . ($set->extras ? '<script type="text/javascript" src="' . $imcepath . '/imce_extras.js"></script>' : '') . '
  <style type="text/css" media="all">@import "' . $imcepath . '/imce.css";</style>
</head>
<body>
<div id="headerdiv">' . theme('table', $header, array(), array(
    'id' => 'headertable',
  )) . '
</div>
<div id="bodydiv" title="' . ($set->extras ? t('Keyboard shortcuts') . ': ' . t('UP(previous), DOWN(next), DELETE, INSERT(add)') : '') . '">' . theme('table', array(), $rows, array(
    'id' => 'bodytable',
  )) . '
</div>
<div id="resize-bar"><div id="resize-bar-in">^</div></div>
<div id="relative-div">
  <div id="info-div">' . t('Directory') . ': ' . ($private && $set->uid != 1 ? imce_relative_path($set->dir, $syspath) : $set->dir) . ($foptions ? $foptions : '') . ($_SESSION['imceuser'] ? '<div>' . t('User') . ': ' . $_SESSION['imceuser']['name'] . ' - ' . l(t('logout'), 'imce/logout') . '</div>' : '') . '
  </div>
</div>
<div id="imagepreview">' . theme('status_messages') . '</div>
<div class="forms">' . $uploadform . $resizeform . '
</div>
</body>
</html>';
  unset($_SESSION['imcelatest']);
  print $output;
  exit;
}