Horde_Core_ActiveSync_Connector::files_browse PHP Method

files_browse() public method

Browse VFS backend.
public files_browse ( string $path ) : array
$path string 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']), '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;
    }

Usage Example

Example #1
0
 /**
  * Returns array of items which contain contact information
  *
  * @param string $type   The search type; ['gal'|'mailbox']
  * @param array $query   The search query. An array containing:
  *  - query:          (array) The search query. Contains at least:
  *                    'query' and 'range'. The rest depends on the type of
  *                    search being performed.
  *                    DEFAULT: none, REQUIRED
  *  - range:          (string)   A range limiter.
  *                     DEFAULT: none (No range used).
  *  - rebuildresults: (boolean)  If true, invalidate any cached search.
  *                    DEFAULT: Use cached search results if available.
  *  - deeptraversal:  (boolean) If true, traverse sub folders.
  *                    @todo NOT IMPLEMENTED YET.
  *
  * @return array  An array containing:
  *  - rows:   An array of search results, limited by $query['range'].
  *  - status: The search store status code.
  *  - total:  The total number of matches (not limited by $query['range']
  */
 public function getSearchResults($type, array $query)
 {
     switch (Horde_String::lower($type)) {
         case 'gal':
             return $this->_searchGal($query);
         case 'mailbox':
             if (!empty($this->_cache)) {
                 $clear_cache = !empty($query['rebuildresults']);
                 unset($query['rebuildresults']);
                 $cache_key = $GLOBALS['registry']->getAuth() . ':HCASD:' . hash('md5', serialize($query));
                 if ($clear_cache) {
                     $this->_cache->expire($cache_key);
                 }
             }
             if (!empty($this->_cache) && $this->_cache->exists($cache_key, 0)) {
                 $results = json_decode($this->_cache->get($cache_key, 0), true);
             } else {
                 try {
                     $results = $this->_searchMailbox($query);
                     if (!empty($this->_cache)) {
                         $this->_cache->set($cache_key, json_encode($results));
                     }
                 } catch (Horde_ActiveSync_Exception $e) {
                     $this->_logger->err($e->getMessage());
                     $results = array();
                 }
             }
             $count = count($results);
             if (!empty($query['range'])) {
                 $range = explode('-', $query['range']);
                 $results = array_slice($results, $range[0], $range[1] - $range[0] + 1);
             }
             return array('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);
     }
 }