You are here

function dropbox_client_metadata in Dropbox Client 7.2

Same name and namespace in other branches
  1. 7.4 dropbox_client.module \dropbox_client_metadata()
  2. 7 dropbox_client.module \dropbox_client_metadata()
  3. 7.3 dropbox_client.module \dropbox_client_metadata()
1 call to dropbox_client_metadata()
dropbox_client_block_view in ./dropbox_client.module
Return a rendered or renderable view of a block.

File

./dropbox_client.module, line 315

Code

function dropbox_client_metadata($path) {
  global $user, $base_path;
  $dropbox = dropbox_client_get_client();
  $dbobj = $dropbox
    ->account();
  $metadata = $dropbox
    ->metadata($path);
  $files = array();
  $destination = $_GET['q'];
  foreach ($metadata->contents as $content) {
    if ($content->is_dir) {
      array_push($files, array(
        'data' => '<a href="' . $base_path . $destination . '?dpath=' . $content->path . '">' . basename($content->path) . "</a>",
        'class' => array(
          $content->icon,
        ),
      ));
    }
    else {
      $media = $dropbox
        ->media($content->path);
      $contentclass = isset($content->icon) ? array(
        $content->icon,
      ) : array(
        "page_white_default",
      );
      array_push($files, array(
        'data' => l(basename($content->path), $media->url),
        'class' => array(
          $content->icon,
        ),
      ));
    }
  }
  $breadcrumb = explode("/", $path);
  $incremental_path = '';

  //Delete empty entries except home
  foreach ($breadcrumb as $i => $bread) {
    if ($i && empty($bread)) {
      unset($breadcrumb[$i]);
    }
  }
  foreach ($breadcrumb as $i => $bread) {
    if (!$i) {
      if (count($breadcrumb) == 1) {
        $breadcrumb[$i] = 'Dropbox Home';
      }
      else {
        $path = '/';
        $breadcrumb[$i] = l('Dropbox Home', $destination, array(
          'query' => array(
            'dpath' => $path,
          ),
        ));
      }
    }
    else {
      if (count($breadcrumb) > $i + 1) {
        $path .= "/" . $bread;
        $path = preg_replace("#(^|[^:])//+#", "\\1/", $path);
        $breadcrumb[$i] = l($bread, $destination, array(
          'query' => array(
            'dpath' => $path,
          ),
        ));
      }
      else {
        $path .= "/" . $bread;
        $path = preg_replace("#(^|[^:])//+#", "\\1/", $path);
        $breadcrumb[$i] = $bread;
      }
    }
  }
  $output = theme('breadcrumb', array(
    'breadcrumb' => $breadcrumb,
  ));
  return $output . theme('dropbox_file_list', array(
    'files' => $files,
  ));
}