diff options
author | Robin Appelman <icewind@owncloud.com> | 2012-02-16 09:44:49 +0100 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2012-02-16 09:44:49 +0100 |
commit | 20553c1afe035b2e020409fd516d0288b748dc7f (patch) | |
tree | 9b7cc32ee2560d86315339b9716c1a790a680afc /3rdparty/Sabre/DAV/Browser | |
parent | 19827b8b35de6192d54bf7600e9e29800c93b21b (diff) | |
download | nextcloud-server-20553c1afe035b2e020409fd516d0288b748dc7f.tar.gz nextcloud-server-20553c1afe035b2e020409fd516d0288b748dc7f.zip |
Revert "remove the 3rdparty files. everything is now in https://gitorious.org/owncloud/3rdparty"
This reverts commit dccdeca2581f705c69eb4266aa646173f588a9de.
Diffstat (limited to '3rdparty/Sabre/DAV/Browser')
-rw-r--r-- | 3rdparty/Sabre/DAV/Browser/GuessContentType.php | 97 | ||||
-rw-r--r-- | 3rdparty/Sabre/DAV/Browser/MapGetToPropFind.php | 54 | ||||
-rw-r--r-- | 3rdparty/Sabre/DAV/Browser/Plugin.php | 285 |
3 files changed, 436 insertions, 0 deletions
diff --git a/3rdparty/Sabre/DAV/Browser/GuessContentType.php b/3rdparty/Sabre/DAV/Browser/GuessContentType.php new file mode 100644 index 00000000000..ee8c698d782 --- /dev/null +++ b/3rdparty/Sabre/DAV/Browser/GuessContentType.php @@ -0,0 +1,97 @@ +<?php + +/** + * GuessContentType plugin + * + * A lot of the built-in File objects just return application/octet-stream + * as a content-type by default. This is a problem for some clients, because + * they expect a correct contenttype. + * + * There's really no accurate, fast and portable way to determine the contenttype + * so this extension does what the rest of the world does, and guesses it based + * on the file extension. + * + * @package Sabre + * @subpackage DAV + * @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved. + * @author Evert Pot (http://www.rooftopsolutions.nl/) + * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License + */ +class Sabre_DAV_Browser_GuessContentType extends Sabre_DAV_ServerPlugin { + + /** + * List of recognized file extensions + * + * Feel free to add more + * + * @var array + */ + public $extensionMap = array( + + // images + 'jpg' => 'image/jpeg', + 'gif' => 'image/gif', + 'png' => 'image/png', + + // groupware + 'ics' => 'text/calendar', + 'vcf' => 'text/x-vcard', + + // text + 'txt' => 'text/plain', + + ); + + /** + * Initializes the plugin + * + * @param Sabre_DAV_Server $server + * @return void + */ + public function initialize(Sabre_DAV_Server $server) { + + // Using a relatively low priority (200) to allow other extensions + // to set the content-type first. + $server->subscribeEvent('afterGetProperties',array($this,'afterGetProperties'),200); + + } + + /** + * Handler for teh afterGetProperties event + * + * @param string $path + * @param array $properties + * @return void + */ + public function afterGetProperties($path, &$properties) { + + if (array_key_exists('{DAV:}getcontenttype', $properties[404])) { + + list(, $fileName) = Sabre_DAV_URLUtil::splitPath($path); + $contentType = $this->getContentType($fileName); + + if ($contentType) { + $properties[200]['{DAV:}getcontenttype'] = $contentType; + unset($properties[404]['{DAV:}getcontenttype']); + } + + } + + } + + /** + * Simple method to return the contenttype + * + * @param string $fileName + * @return string + */ + protected function getContentType($fileName) { + + // Just grabbing the extension + $extension = strtolower(substr($fileName,strrpos($fileName,'.')+1)); + if (isset($this->extensionMap[$extension])) + return $this->extensionMap[$extension]; + + } + +} diff --git a/3rdparty/Sabre/DAV/Browser/MapGetToPropFind.php b/3rdparty/Sabre/DAV/Browser/MapGetToPropFind.php new file mode 100644 index 00000000000..a66b57a3a90 --- /dev/null +++ b/3rdparty/Sabre/DAV/Browser/MapGetToPropFind.php @@ -0,0 +1,54 @@ +<?php + +/** + * This is a simple plugin that will map any GET request for non-files to + * PROPFIND allprops-requests. + * + * This should allow easy debugging of PROPFIND + * + * @package Sabre + * @subpackage DAV + * @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved. + * @author Evert Pot (http://www.rooftopsolutions.nl/) + * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License + */ +class Sabre_DAV_Browser_MapGetToPropFind extends Sabre_DAV_ServerPlugin { + + /** + * reference to server class + * + * @var Sabre_DAV_Server + */ + protected $server; + + /** + * Initializes the plugin and subscribes to events + * + * @param Sabre_DAV_Server $server + * @return void + */ + public function initialize(Sabre_DAV_Server $server) { + + $this->server = $server; + $this->server->subscribeEvent('beforeMethod',array($this,'httpGetInterceptor')); + } + + /** + * This method intercepts GET requests to non-files, and changes it into an HTTP PROPFIND request + * + * @param string $method + * @return bool + */ + public function httpGetInterceptor($method, $uri) { + + if ($method!='GET') return true; + + $node = $this->server->tree->getNodeForPath($uri); + if ($node instanceof Sabre_DAV_IFile) return; + + $this->server->invokeMethod('PROPFIND',$uri); + return false; + + } + +} diff --git a/3rdparty/Sabre/DAV/Browser/Plugin.php b/3rdparty/Sabre/DAV/Browser/Plugin.php new file mode 100644 index 00000000000..cd5617babb1 --- /dev/null +++ b/3rdparty/Sabre/DAV/Browser/Plugin.php @@ -0,0 +1,285 @@ +<?php + +/** + * Browser Plugin + * + * This plugin provides a html representation, so that a WebDAV server may be accessed + * using a browser. + * + * The class intercepts GET requests to collection resources and generates a simple + * html index. + * + * @package Sabre + * @subpackage DAV + * @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved. + * @author Evert Pot (http://www.rooftopsolutions.nl/) + * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License + */ +class Sabre_DAV_Browser_Plugin extends Sabre_DAV_ServerPlugin { + + /** + * reference to server class + * + * @var Sabre_DAV_Server + */ + protected $server; + + /** + * enableEditing + * + * @var bool + */ + protected $enablePost = true; + + /** + * Creates the object. + * + * By default it will allow file creation and uploads. + * Specify the first argument as false to disable this + * + * @param bool $enablePost + * @return void + */ + public function __construct($enablePost=true) { + + $this->enablePost = $enablePost; + + } + + /** + * Initializes the plugin and subscribes to events + * + * @param Sabre_DAV_Server $server + * @return void + */ + public function initialize(Sabre_DAV_Server $server) { + + $this->server = $server; + $this->server->subscribeEvent('beforeMethod',array($this,'httpGetInterceptor')); + if ($this->enablePost) $this->server->subscribeEvent('unknownMethod',array($this,'httpPOSTHandler')); + } + + /** + * This method intercepts GET requests to collections and returns the html + * + * @param string $method + * @return bool + */ + public function httpGetInterceptor($method, $uri) { + + if ($method!='GET') return true; + + try { + $node = $this->server->tree->getNodeForPath($uri); + } catch (Sabre_DAV_Exception_FileNotFound $e) { + // We're simply stopping when the file isn't found to not interfere + // with other plugins. + return; + } + if ($node instanceof Sabre_DAV_IFile) + return; + + $this->server->httpResponse->sendStatus(200); + $this->server->httpResponse->setHeader('Content-Type','text/html; charset=utf-8'); + + $this->server->httpResponse->sendBody( + $this->generateDirectoryIndex($uri) + ); + + return false; + + } + + /** + * Handles POST requests for tree operations + * + * This method is not yet used. + * + * @param string $method + * @return bool + */ + public function httpPOSTHandler($method, $uri) { + + if ($method!='POST') return true; + if (isset($_POST['sabreAction'])) switch($_POST['sabreAction']) { + + case 'mkcol' : + if (isset($_POST['name']) && trim($_POST['name'])) { + // Using basename() because we won't allow slashes + list(, $folderName) = Sabre_DAV_URLUtil::splitPath(trim($_POST['name'])); + $this->server->createDirectory($uri . '/' . $folderName); + } + break; + case 'put' : + if ($_FILES) $file = current($_FILES); + else break; + $newName = trim($file['name']); + list(, $newName) = Sabre_DAV_URLUtil::splitPath(trim($file['name'])); + if (isset($_POST['name']) && trim($_POST['name'])) + $newName = trim($_POST['name']); + + // Making sure we only have a 'basename' component + list(, $newName) = Sabre_DAV_URLUtil::splitPath($newName); + + + if (is_uploaded_file($file['tmp_name'])) { + $parent = $this->server->tree->getNodeForPath(trim($uri,'/')); + $parent->createFile($newName,fopen($file['tmp_name'],'r')); + } + + } + $this->server->httpResponse->setHeader('Location',$this->server->httpRequest->getUri()); + return false; + + } + + /** + * Escapes a string for html. + * + * @param string $value + * @return void + */ + public function escapeHTML($value) { + + return htmlspecialchars($value,ENT_QUOTES,'UTF-8'); + + } + + /** + * Generates the html directory index for a given url + * + * @param string $path + * @return string + */ + public function generateDirectoryIndex($path) { + + $html = "<html> +<head> + <title>Index for " . $this->escapeHTML($path) . "/ - SabreDAV " . Sabre_DAV_Version::VERSION . "</title> + <style type=\"text/css\"> body { Font-family: arial}</style> +</head> +<body> + <h1>Index for " . $this->escapeHTML($path) . "/</h1> + <table> + <tr><th>Name</th><th>Type</th><th>Size</th><th>Last modified</th></tr> + <tr><td colspan=\"4\"><hr /></td></tr>"; + + $files = $this->server->getPropertiesForPath($path,array( + '{DAV:}displayname', + '{DAV:}resourcetype', + '{DAV:}getcontenttype', + '{DAV:}getcontentlength', + '{DAV:}getlastmodified', + ),1); + + $parent = $this->server->tree->getNodeForPath($path); + + + if ($path) { + + list($parentUri) = Sabre_DAV_URLUtil::splitPath($path); + $fullPath = Sabre_DAV_URLUtil::encodePath($this->server->getBaseUri() . $parentUri); + + $html.= "<tr> +<td><a href=\"{$fullPath}\">..</a></td> +<td>[parent]</td> +<td></td> +<td></td> +</tr>"; + + } + + foreach($files as $k=>$file) { + + // This is the current directory, we can skip it + if (rtrim($file['href'],'/')==$path) continue; + + list(, $name) = Sabre_DAV_URLUtil::splitPath($file['href']); + + $type = null; + + + if (isset($file[200]['{DAV:}resourcetype'])) { + $type = $file[200]['{DAV:}resourcetype']->getValue(); + + // resourcetype can have multiple values + if (!is_array($type)) $type = array($type); + + foreach($type as $k=>$v) { + + // Some name mapping is preferred + switch($v) { + case '{DAV:}collection' : + $type[$k] = 'Collection'; + break; + case '{DAV:}principal' : + $type[$k] = 'Principal'; + break; + case '{urn:ietf:params:xml:ns:carddav}addressbook' : + $type[$k] = 'Addressbook'; + break; + case '{urn:ietf:params:xml:ns:caldav}calendar' : + $type[$k] = 'Calendar'; + break; + } + + } + $type = implode(', ', $type); + } + + // If no resourcetype was found, we attempt to use + // the contenttype property + if (!$type && isset($file[200]['{DAV:}getcontenttype'])) { + $type = $file[200]['{DAV:}getcontenttype']; + } + if (!$type) $type = 'Unknown'; + + $size = isset($file[200]['{DAV:}getcontentlength'])?(int)$file[200]['{DAV:}getcontentlength']:''; + $lastmodified = isset($file[200]['{DAV:}getlastmodified'])?$file[200]['{DAV:}getlastmodified']->getTime()->format(DateTime::ATOM):''; + + $fullPath = Sabre_DAV_URLUtil::encodePath('/' . trim($this->server->getBaseUri() . ($path?$path . '/':'') . $name,'/')); + + $displayName = isset($file[200]['{DAV:}displayname'])?$file[200]['{DAV:}displayname']:$name; + + $name = $this->escapeHTML($name); + $displayName = $this->escapeHTML($displayName); + $type = $this->escapeHTML($type); + + $html.= "<tr> +<td><a href=\"{$fullPath}\">{$displayName}</a></td> +<td>{$type}</td> +<td>{$size}</td> +<td>{$lastmodified}</td> +</tr>"; + + } + + $html.= "<tr><td colspan=\"4\"><hr /></td></tr>"; + + if ($this->enablePost && $parent instanceof Sabre_DAV_ICollection) { + $html.= '<tr><td><form method="post" action=""> + <h3>Create new folder</h3> + <input type="hidden" name="sabreAction" value="mkcol" /> + Name: <input type="text" name="name" /><br /> + <input type="submit" value="create" /> + </form> + <form method="post" action="" enctype="multipart/form-data"> + <h3>Upload file</h3> + <input type="hidden" name="sabreAction" value="put" /> + Name (optional): <input type="text" name="name" /><br /> + File: <input type="file" name="file" /><br /> + <input type="submit" value="upload" /> + </form> + </td></tr>'; + } + + $html.= "</table> + <address>Generated by SabreDAV " . Sabre_DAV_Version::VERSION ."-". Sabre_DAV_Version::STABILITY . " (c)2007-2011 <a href=\"http://code.google.com/p/sabredav/\">http://code.google.com/p/sabredav/</a></address> +</body> +</html>"; + + return $html; + + } + +} |