Skip to content

Commit

Permalink
Implement DocumentLibrary support in Core.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Jan 6, 2014
1 parent aa9ed44 commit e4c421b
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 2 deletions.
79 changes: 79 additions & 0 deletions framework/Core/lib/Horde/Core/ActiveSync/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,85 @@ public function contacts_getGal()
return $this->_gal;
}

/**
* Browse VFS backend.
*
* @param string $path The path to browse/fetch. This should be in UNC
* format with the "server" portion specifying
* backend name. e.g., \\file\mike\file.txt or
* \\sql\mike\file.txt
*
* @return array An array of data arrays with the following structure:
* linkid: (string) The UNC path for this resource.
* name: (string) The display name of the resource.
* content-length: (integer) The byte size of the resource (if a file).
* modified: (Horde_Date) The modification time of the resource, if
* available.
* create: (Horde_Date) The creation time of the resource, if
* available.
* is_folder: (boolean) True if the resource is a folder.
* data: (Horde_Stream) The data, if resource is a file.
* content-type: (string) The MIME type of the file resource, if
* available.
* @since 2.12.0
*/
public function files_browse($path)
{
if (!$app = $this->_registry->hasInterface('files')) {
return false;
}

// Save for later.
$original_path = $path;

// Normalize
$path = str_replace('\\', '/', $path);

// Get the "server" name.
$regex = '=^//([a-zA-Z0-9-]+)/(.*)=';
if (preg_match($regex, $path, $results) === false) {
return false;
}
$backend = $app . '/' . $results[1];
$path = $backend . '//' . $results[2];

try {
$results = $this->_registry->files->browse($path);
} catch (Horde_Exception $e) {
throw new Horde_ActiveSync_Exception($e);
}

$files = array();

// An explicit file requested?
if (!empty($results['data'])) {
$data = new Horde_Stream();
$data->add($results['data']);
$files[] = array(
'linkid' => $original_path,
'name' => $results['name'],
'content-length' => $results['contentlength'],
'modified' => new Horde_Date($results['mtime']),
'created' => new Horde_Date($results['mtime']), // No creation date?
'is_folder' => false,
'data' => $data);
} else {
foreach ($results as $id => $result) {
$file = array('name' => $result['name']);
$file['is_folder'] = $result['browseable'];
$file['modified'] = new Horde_Date($result['modified']);
$file['created'] = clone $file['modified'];
$file['linkid'] = str_replace($backend, '', $id);
if (!empty($result['contentlength'])) {
$file['content-length'] = $result['contentlength'];
}
$files[] = $file;
}
}

return $files;
}

/**
* List all tasks in the user's default tasklist.
*
Expand Down
13 changes: 11 additions & 2 deletions framework/Core/lib/Horde/Core/ActiveSync/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class Horde_Core_ActiveSync_Driver extends Horde_ActiveSync_Driver_Base
* DEFAULT: none (No email support will be provided).
* - cache: (Horde_Cache) A cache object to store certain types of
* data, such as mailbox search results.
* @since 2.11.3
* @since 2.12.0
*/
public function __construct(array $params = array())
{
Expand Down Expand Up @@ -1354,7 +1354,8 @@ public function itemOperationsGetAttachmentData($filereference)
*/
public function itemOperationsGetDocumentLibraryLink($linkid, $cred)
{
throw new Horde_ActiveSync_Exception('Not Supported');
$file = $this->_connector->files_browse($linkid);
return array_pop($file);
}

/**
Expand Down Expand Up @@ -1739,6 +1740,14 @@ public function getSearchResults($type, array $query)
'rows' => $results,
'total' => $count,
'status' => Horde_ActiveSync_Request_Search::STORE_STATUS_SUCCESS);

case 'documentlibrary':
foreach ($query['query'][0] as $q) {
if (!empty($q['DocumentLibrary:LinkId'])) {
$results = $this->_connector->files_browse($q['DocumentLibrary:LinkId']);
}
}
return array('rows' => $results, 'total' => count($results), 'status' => Horde_ActiveSync_Request_Search::STORE_STATUS_SUCCESS);
}
}

Expand Down

0 comments on commit e4c421b

Please sign in to comment.