You are here

function cmis_browser_browse in CMIS API 6

Build CMIS repository browse page.

1 string reference to 'cmis_browser_browse'
cmis_browser_menu in cmis_browser/cmis_browser.module
Implementation of hook_menu() for CMIS browser module.

File

cmis_browser/cmis_browser.module, line 85

Code

function cmis_browser_browse() {
  module_load_include('api.inc', 'cmis');
  drupal_add_css(drupal_get_path('module', 'cmis_browser') . '/cmis_browser.css');
  $contents = '';
  $contents .= drupal_get_form('cmis_browser_browse_form');

  // Get the repo space path from request
  $folder_img = theme('image', drupal_get_path('module', 'cmis_browser') . '/images/space.gif');
  $file_img = theme('image', drupal_get_path('module', 'cmis_browser') . '/images/file.png');
  $next_img = theme('image', drupal_get_path('module', 'cmis_browser') . '/images/next.gif');
  $parts = explode('/', $_GET['q']);
  $path = implode('/', array_slice($parts, 2));
  if ($path) {
    $path = '/' . $path;
  }
  $contents .= '<div id="cmis-breadcrumb">';

  // Generate Breadcrumb
  $currentpath = '';
  $bcarray = array_slice($parts, 2);
  foreach ($bcarray as $space) {
    $currentpath .= '/' . $space;
    $pagelink = l($space, 'cmis/browser' . $currentpath);
    $contents .= $pagelink;
    if ($space != end($bcarray)) {
      $contents .= $next_img . ' ';
    }
  }
  $contents .= '</div>';

  // Invoke CMIS service
  $repository = cmisapi_getRepositoryInfo();
  $folderObject = null;
  if (isset($_GET['id'])) {
    $folderObject = cmisapi_getProperties($repository->repositoryId, urldecode($_GET['id']));
  }
  elseif ($path) {
    $folderObject = cmisapi_getProperties($repository->repositoryId, drupal_urlencode($path));
  }
  else {
    $folderId_parts = explode('/', $repository->rootFolderId);
    $path = '/' . $folderId_parts[sizeof($folderId_parts) - 1];
    $folderObject = cmisapi_getProperties($repository->repositoryId, $path);
  }
  $children = cmisapi_getChildren($repository->repositoryId, $folderObject->id);
  if (false === $children) {
    $contents = 'Unable to communicate with repository.';
  }
  else {
    $header = array(
      t('name'),
      t('type'),
      t('size'),
      t('author'),
      t('last modified'),
    );
    $folder_img = theme('image', drupal_get_path('module', 'cmis_browser') . '/images/space.gif');
    $file_img = theme('image', drupal_get_path('module', 'cmis_browser') . '/images/file.png');
    if (isset($_GET['id'])) {
      if ($folderParents = cmisapi_getObjectParents($repository->repositoryId, $folderObject->id)) {
        $folderParentObject = end($folderParents);
        $folderParentObject->title = '..';
        $children = array_merge(array(
          $folderParentObject,
        ), $children);
      }
    }
    foreach ($children as $child) {
      $summary = $child->summary;
      $type = $child->type;
      $updated = date_create($entry->updated);
      $updatedStr = date_format($updated, 'n/j/Y g:i A');
      if ($type == 'folder') {
        if (isset($_GET['id'])) {
          $folderlink = l($child->title, 'cmis/browser', array(
            'query' => array(
              'id' => $child->id,
            ),
          ));
        }
        else {
          $folderlink = l($child->title, 'cmis/browser' . $path . '/' . $child->title);
        }
        $rows[] = array(
          $folder_img . ' ' . $folderlink,
          'Space',
          '',
          $child->author,
          $updatedStr,
        );
      }
      else {
        $size = $child->size;
        $docType = $child->contentMimeType;
        $icon = $child->icon;
        $documentLink = l($child->title, 'cmis/get', array(
          'query' => array(
            'id' => $child->id,
          ),
        ));
        $rows[] = array(
          $file_img . $documentLink,
          $docType,
          number_format($size / 1000, 2, '.', ',') . ' K',
          $child->author,
          $updatedStr,
        );
      }
    }
    $contents .= theme('table', $header, $rows);
  }
  return $contents;
}