本文整理汇总了PHP中Sabre\DAV\URLUtil::encodePath方法的典型用法代码示例。如果您正苦于以下问题:PHP URLUtil::encodePath方法的具体用法?PHP URLUtil::encodePath怎么用?PHP URLUtil::encodePath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sabre\DAV\URLUtil
的用法示例。
在下文中一共展示了URLUtil::encodePath方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: serialize
/**
* serialize
*
* @param DAV\Server $server
* @param \DOMElement $dom
* @return void
*/
public function serialize(DAV\Server $server, \DOMElement $dom)
{
$document = $dom->ownerDocument;
$properties = $this->responseProperties;
$xresponse = $document->createElement('d:response');
$dom->appendChild($xresponse);
$uri = DAV\URLUtil::encodePath($this->href);
// Adding the baseurl to the beginning of the url
$uri = $server->getBaseUri() . $uri;
$xresponse->appendChild($document->createElement('d:href', $uri));
// The properties variable is an array containing properties, grouped by
// HTTP status
foreach ($properties as $httpStatus => $propertyGroup) {
// The 'href' is also in this array, and it's special cased.
// We will ignore it
if ($httpStatus == 'href') {
continue;
}
// If there are no properties in this group, we can also just carry on
if (!count($propertyGroup)) {
continue;
}
$xpropstat = $document->createElement('d:propstat');
$xresponse->appendChild($xpropstat);
$xprop = $document->createElement('d:prop');
$xpropstat->appendChild($xprop);
$nsList = $server->xmlNamespaces;
foreach ($propertyGroup as $propertyName => $propertyValue) {
$propName = null;
preg_match('/^{([^}]*)}(.*)$/', $propertyName, $propName);
// special case for empty namespaces
if ($propName[1] == '') {
$currentProperty = $document->createElement($propName[2]);
$xprop->appendChild($currentProperty);
$currentProperty->setAttribute('xmlns', '');
} else {
if (!isset($nsList[$propName[1]])) {
$nsList[$propName[1]] = 'x' . count($nsList);
}
// If the namespace was defined in the top-level xml namespaces, it means
// there was already a namespace declaration, and we don't have to worry about it.
if (isset($server->xmlNamespaces[$propName[1]])) {
$currentProperty = $document->createElement($nsList[$propName[1]] . ':' . $propName[2]);
} else {
$currentProperty = $document->createElementNS($propName[1], $nsList[$propName[1]] . ':' . $propName[2]);
}
$xprop->appendChild($currentProperty);
}
if (is_scalar($propertyValue)) {
$text = $document->createTextNode($propertyValue);
$currentProperty->appendChild($text);
} elseif ($propertyValue instanceof DAV\PropertyInterface) {
$propertyValue->serialize($server, $currentProperty);
} elseif (!is_null($propertyValue)) {
throw new DAV\Exception('Unknown property value type: ' . gettype($propertyValue) . ' for property: ' . $propertyName);
}
}
$xpropstat->appendChild($document->createElement('d:status', $server->httpResponse->getStatusMessage($httpStatus)));
}
}
示例2: serialize
/**
* Serializes this property.
*
* It will additionally prepend the href property with the server's base uri.
*
* @param DAV\Server $server
* @param \DOMElement $dom
* @return void
*/
function serialize(DAV\Server $server, \DOMElement $dom)
{
$prefix = $server->xmlNamespaces['DAV:'];
$elem = $dom->ownerDocument->createElement($prefix . ':href');
if ($this->autoPrefix) {
$value = $server->getBaseUri() . DAV\URLUtil::encodePath($this->href);
} else {
$value = $this->href;
}
$elem->appendChild($dom->ownerDocument->createTextNode($value));
$dom->appendChild($elem);
}
示例3: generateDirectoryIndex
/**
* @brief Creates the directory listing for the given path.
*
* @param string $path which should be displayed
*/
public function generateDirectoryIndex($path)
{
// (owner_id = channel_id) is visitor owner of this directory?
$is_owner = local_channel() && $this->auth->owner_id == local_channel() ? true : false;
if ($this->auth->getTimezone()) {
date_default_timezone_set($this->auth->getTimezone());
}
require_once 'include/conversation.php';
require_once 'include/text.php';
if ($this->auth->owner_nick) {
$html = profile_tabs(get_app(), $is_owner ? true : false, $this->auth->owner_nick);
}
$files = $this->server->getPropertiesForPath($path, array('{DAV:}displayname', '{DAV:}resourcetype', '{DAV:}getcontenttype', '{DAV:}getcontentlength', '{DAV:}getlastmodified'), 1);
$parent = $this->server->tree->getNodeForPath($path);
$parentpath = array();
// only show parent if not leaving /cloud/; TODO how to improve this?
if ($path && $path != "cloud") {
list($parentUri) = DAV\URLUtil::splitPath($path);
$fullPath = DAV\URLUtil::encodePath($this->server->getBaseUri() . $parentUri);
$parentpath['icon'] = $this->enableAssets ? '<a href="' . $fullPath . '"><img src="' . $this->getAssetUrl('icons/parent' . $this->iconExtension) . '" width="24" alt="' . t('parent') . '"></a>' : '';
$parentpath['path'] = $fullPath;
}
$f = array();
foreach ($files as $file) {
$ft = array();
$type = null;
// This is the current directory, we can skip it
if (rtrim($file['href'], '/') == $path) {
continue;
}
list(, $name) = DAV\URLUtil::splitPath($file['href']);
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] = t('Collection');
break;
case '{DAV:}principal':
$type[$k] = t('Principal');
break;
case '{urn:ietf:params:xml:ns:carddav}addressbook':
$type[$k] = t('Addressbook');
break;
case '{urn:ietf:params:xml:ns:caldav}calendar':
$type[$k] = t('Calendar');
break;
case '{urn:ietf:params:xml:ns:caldav}schedule-inbox':
$type[$k] = t('Schedule Inbox');
break;
case '{urn:ietf:params:xml:ns:caldav}schedule-outbox':
$type[$k] = t('Schedule Outbox');
break;
case '{http://calendarserver.org/ns/}calendar-proxy-read':
$type[$k] = 'Proxy-Read';
break;
case '{http://calendarserver.org/ns/}calendar-proxy-write':
$type[$k] = 'Proxy-Write';
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 = t('Unknown');
}
$size = isset($file[200]['{DAV:}getcontentlength']) ? (int) $file[200]['{DAV:}getcontentlength'] : '';
$lastmodified = isset($file[200]['{DAV:}getlastmodified']) ? $file[200]['{DAV:}getlastmodified']->getTime()->format('Y-m-d H:i:s') : '';
$fullPath = DAV\URLUtil::encodePath('/' . trim($this->server->getBaseUri() . ($path ? $path . '/' : '') . $name, '/'));
$displayName = isset($file[200]['{DAV:}displayname']) ? $file[200]['{DAV:}displayname'] : $name;
$displayName = $this->escapeHTML($displayName);
$type = $this->escapeHTML($type);
$icon = '';
if ($this->enableAssets) {
$node = $this->server->tree->getNodeForPath(($path ? $path . '/' : '') . $name);
foreach (array_reverse($this->iconMap) as $class => $iconName) {
if ($node instanceof $class) {
$icon = '<a href="' . $fullPath . '"><img src="' . $this->getAssetUrl($iconName . $this->iconExtension) . '" alt="" width="24"></a>';
break;
}
}
}
$parentHash = '';
$owner = $this->auth->owner_id;
$splitPath = explode('/', $fullPath);
//.........这里部分代码省略.........
示例4: serialize
/**
* Serializes the property into a DOMElement.
*
* @param DAV\Server $server
* @param \DOMElement $node
* @return void
*/
public function serialize(DAV\Server $server, \DOMElement $node)
{
$prefix = $server->xmlNamespaces['DAV:'];
switch ($this->type) {
case self::UNAUTHENTICATED:
$node->appendChild($node->ownerDocument->createElement($prefix . ':unauthenticated'));
break;
case self::AUTHENTICATED:
$node->appendChild($node->ownerDocument->createElement($prefix . ':authenticated'));
break;
case self::HREF:
$href = $node->ownerDocument->createElement($prefix . ':href');
$href->nodeValue = $server->getBaseUri() . DAV\URLUtil::encodePath($this->href);
$node->appendChild($href);
break;
}
}
示例5: generateDirectoryIndex
public function generateDirectoryIndex($path)
{
$html = "<html>\n<head>\n <title>Index for " . $this->escapeHTML($path) . "/ - SabreDAV " . DAV\Version::VERSION . "</title>\n <style type=\"text/css\"> body { Font-family: arial}</style>\n</head>\n<body>\n <h1>Index for " . $this->escapeHTML($path) . "/</h1>\n <table>\n <tr><th>Name</th><th>Type</th><th>Size</th><th>Last modified</th></tr>\n <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) = DAV\URLUtil::splitPath($path);
$fullPath = DAV\URLUtil::encodePath($this->server->getBaseUri() . $parentUri);
$html .= "<tr>\n<td><a href=\"{$fullPath}\">..</a></td>\n<td>[parent]</td>\n<td></td>\n<td></td>\n</tr>";
}
foreach ($files as $k => $file) {
// This is the current directory, we can skip it
if (rtrim($file['href'], '/') == $path) {
continue;
}
list(, $name) = 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 = 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>\n<td><a href=\"{$fullPath}\">{$displayName}</a></td>\n<td>{$type}</td>\n<td>{$size}</td>\n<td>{$lastmodified}</td>\n</tr>";
}
$html .= "<tr><td colspan=\"4\"><hr /></td></tr>";
if ($this->enablePost && $parent instanceof DAV\ICollection) {
$html .= '<tr><td>
<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>\n <address>Generated by SabreDAV " . DAV\Version::VERSION . "-" . DAV\Version::STABILITY . " (c)2007-2012 <a href=\"http://code.google.com/p/sabredav/\">http://code.google.com/p/sabredav/</a></address>\n</body>\n</html>";
return $html;
}
示例6: generateDirectoryIndex
/**
* Generates the html directory index for a given url
*
* @param string $path
* @return string
*/
public function generateDirectoryIndex($path)
{
$version = '';
if (DAV\Server::$exposeVersion) {
$version = DAV\Version::VERSION . "-" . DAV\Version::STABILITY;
}
$html = "<html>\n<head>\n <title>Index for " . $this->escapeHTML($path) . "/ - SabreDAV " . $version . "</title>\n <style type=\"text/css\">\n body { Font-family: arial}\n h1 { font-size: 150% }\n </style>\n ";
if ($this->enableAssets) {
$html .= '<link rel="shortcut icon" href="' . $this->getAssetUrl('favicon.ico') . '" type="image/vnd.microsoft.icon" />';
}
$html .= "</head>\n<body>\n <h1>Index for " . $this->escapeHTML($path) . "/</h1>\n <table>\n <tr><th width=\"24\"></th><th>Name</th><th>Type</th><th>Size</th><th>Last modified</th></tr>\n <tr><td colspan=\"5\"><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) = DAV\URLUtil::splitPath($path);
$fullPath = DAV\URLUtil::encodePath($this->server->getBaseUri() . $parentUri);
$icon = $this->enableAssets ? '<a href="' . $fullPath . '"><img src="' . $this->getAssetUrl('icons/parent' . $this->iconExtension) . '" width="24" alt="Parent" /></a>' : '';
$html .= "<tr>\n <td>{$icon}</td>\n <td><a href=\"{$fullPath}\">..</a></td>\n <td>[parent]</td>\n <td></td>\n <td></td>\n </tr>";
}
foreach ($files as $file) {
// This is the current directory, we can skip it
if (rtrim($file['href'], '/') == $path) {
continue;
}
list(, $name) = 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;
case '{urn:ietf:params:xml:ns:caldav}schedule-inbox':
$type[$k] = 'Schedule Inbox';
break;
case '{urn:ietf:params:xml:ns:caldav}schedule-outbox':
$type[$k] = 'Schedule Outbox';
break;
case '{http://calendarserver.org/ns/}calendar-proxy-read':
$type[$k] = 'Proxy-Read';
break;
case '{http://calendarserver.org/ns/}calendar-proxy-write':
$type[$k] = 'Proxy-Write';
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 = DAV\URLUtil::encodePath('/' . trim($this->server->getBaseUri() . ($path ? $path . '/' : '') . $name, '/'));
$displayName = isset($file[200]['{DAV:}displayname']) ? $file[200]['{DAV:}displayname'] : $name;
$displayName = $this->escapeHTML($displayName);
$type = $this->escapeHTML($type);
$icon = '';
if ($this->enableAssets) {
$node = $this->server->tree->getNodeForPath(($path ? $path . '/' : '') . $name);
foreach (array_reverse($this->iconMap) as $class => $iconName) {
if ($node instanceof $class) {
$icon = '<a href="' . $fullPath . '"><img src="' . $this->getAssetUrl($iconName . $this->iconExtension) . '" alt="" width="24" /></a>';
break;
}
}
}
$html .= "<tr>\n <td>{$icon}</td>\n <td><a href=\"{$fullPath}\">{$displayName}</a></td>\n <td>{$type}</td>\n <td>{$size}</td>\n <td>{$lastmodified}</td>\n </tr>";
}
$html .= "<tr><td colspan=\"5\"><hr /></td></tr>";
$output = '';
if ($this->enablePost) {
$this->server->broadcastEvent('onHTMLActionsPanel', array($parent, &$output));
}
//.........这里部分代码省略.........
示例7: beforeGetProperties
/**
* beforeGetProperties
*
* This method handler is invoked before any after properties for a
* resource are fetched. This allows us to add in any CalDAV specific
* properties.
*
* @param string $path
* @param DAV\INode $node
* @param array $requestedProperties
* @param array $returnedProperties
* @return void
*/
public function beforeGetProperties($path, DAV\INode $node, &$requestedProperties, &$returnedProperties)
{
if ($node instanceof DAVACL\IPrincipal) {
// calendar-home-set property
$calHome = '{' . self::NS_CALDAV . '}calendar-home-set';
if (in_array($calHome, $requestedProperties)) {
$principalId = $node->getName();
$calendarHomePath = self::CALENDAR_ROOT . '/' . $principalId . '/';
unset($requestedProperties[array_search($calHome, $requestedProperties)]);
$returnedProperties[200][$calHome] = new DAV\Property\Href($calendarHomePath);
}
// schedule-outbox-URL property
$scheduleProp = '{' . self::NS_CALDAV . '}schedule-outbox-URL';
if (in_array($scheduleProp, $requestedProperties)) {
$principalId = $node->getName();
$outboxPath = self::CALENDAR_ROOT . '/' . $principalId . '/outbox';
unset($requestedProperties[array_search($scheduleProp, $requestedProperties)]);
$returnedProperties[200][$scheduleProp] = new DAV\Property\Href($outboxPath);
}
// calendar-user-address-set property
$calProp = '{' . self::NS_CALDAV . '}calendar-user-address-set';
if (in_array($calProp, $requestedProperties)) {
$addresses = $node->getAlternateUriSet();
$addresses[] = $this->server->getBaseUri() . DAV\URLUtil::encodePath($node->getPrincipalUrl() . '/');
unset($requestedProperties[array_search($calProp, $requestedProperties)]);
$returnedProperties[200][$calProp] = new DAV\Property\HrefList($addresses, false);
}
// These two properties are shortcuts for ical to easily find
// other principals this principal has access to.
$propRead = '{' . self::NS_CALENDARSERVER . '}calendar-proxy-read-for';
$propWrite = '{' . self::NS_CALENDARSERVER . '}calendar-proxy-write-for';
if (in_array($propRead, $requestedProperties) || in_array($propWrite, $requestedProperties)) {
$aclPlugin = $this->server->getPlugin('acl');
$membership = $aclPlugin->getPrincipalMembership($path);
$readList = array();
$writeList = array();
foreach ($membership as $group) {
$groupNode = $this->server->tree->getNodeForPath($group);
// If the node is either ap proxy-read or proxy-write
// group, we grab the parent principal and add it to the
// list.
if ($groupNode instanceof Principal\IProxyRead) {
list($readList[]) = DAV\URLUtil::splitPath($group);
}
if ($groupNode instanceof Principal\IProxyWrite) {
list($writeList[]) = DAV\URLUtil::splitPath($group);
}
}
if (in_array($propRead, $requestedProperties)) {
unset($requestedProperties[$propRead]);
$returnedProperties[200][$propRead] = new DAV\Property\HrefList($readList);
}
if (in_array($propWrite, $requestedProperties)) {
unset($requestedProperties[$propWrite]);
$returnedProperties[200][$propWrite] = new DAV\Property\HrefList($writeList);
}
}
// notification-URL property
$notificationUrl = '{' . self::NS_CALENDARSERVER . '}notification-URL';
if (($index = array_search($notificationUrl, $requestedProperties)) !== false) {
$principalId = $node->getName();
$calendarHomePath = 'calendars/' . $principalId . '/notifications/';
unset($requestedProperties[$index]);
$returnedProperties[200][$notificationUrl] = new DAV\Property\Href($calendarHomePath);
}
}
// instanceof IPrincipal
if ($node instanceof Notifications\INode) {
$propertyName = '{' . self::NS_CALENDARSERVER . '}notificationtype';
if (($index = array_search($propertyName, $requestedProperties)) !== false) {
$returnedProperties[200][$propertyName] = $node->getNotificationType();
unset($requestedProperties[$index]);
}
}
// instanceof Notifications_INode
if ($node instanceof ICalendarObject) {
// The calendar-data property is not supposed to be a 'real'
// property, but in large chunks of the spec it does act as such.
// Therefore we simply expose it as a property.
$calDataProp = '{' . Plugin::NS_CALDAV . '}calendar-data';
if (in_array($calDataProp, $requestedProperties)) {
unset($requestedProperties[$calDataProp]);
$val = $node->get();
if (is_resource($val)) {
$val = stream_get_contents($val);
}
// Taking out \r to not screw up the xml output
//.........这里部分代码省略.........