/** * Set data and parse for properties * * @param string data The data */ public function setData($data) { static $trans; parent::setData($data); // Get the NamespacePrefix $ns = $this->getNamespacePrefix(); // Select properties which should be set foreach (array(FALSE => $this->getNode('/' . $ns . ':propertyupdate/' . $ns . ':set/' . $ns . ':prop'), TRUE => $this->getNode('/' . $ns . ':propertyupdate/' . $ns . ':remove/' . $ns . ':prop')) as $remove => $propupdate) { if (!$propupdate) { continue; } // Copied from WebdavPropFindRequest::setData() foreach ($propupdate->children as $node) { $name = $node->getName(); $ns = 'xmlns'; $nsprefix = ''; if (($p = strpos($name, ':')) !== FALSE) { $ns .= ':' . ($nsprefix = substr($name, 0, $p)); $name = substr($name, $p + 1); } $p = new WebdavProperty($name, $this->decode($node->getContent())); if ($nsname = $node->getAttribute($ns)) { $p->setNamespaceName($nsname); if ($nsprefix) { $p->setNamespacePrefix($nsprefix); } } $this->addProperty($p, $remove); } } }
/** * Set data and parse for properties * * @param string data The data */ public function setData($data) { parent::setData($data); // Set properties if (!$this->getNode('/propfind/allprop') && ($propfind = $this->getNode('/propfind/prop'))) { foreach ($propfind->children as $node) { $name = $node->getName(); $ns = 'xmlns'; $nsprefix = ''; if (($p = strpos($name, ':')) !== FALSE) { $ns .= ':' . ($nsprefix = substr($name, 0, $p)); $name = substr($name, $p + 1); } $p = new WebdavProperty($name); if ($nsname = $node->getAttribute($ns)) { $p->setNamespaceName($nsname); if ($nsprefix) { $p->setNamespacePrefix($nsprefix); } } $this->addProperty($p); } } }
/** * Put a file * * @param string filename * @param mixed data * @param string resourcetype, default NULL * @return bool new * @throws org.webdav.OperationNotAllowedException * @throws org.webdav.OperationFailedException */ public function put($filename, $data, $resourcetype = NULL) { $uri = $this->base . $filename; if (is_dir($uri)) { throw new OperationNotAllowedException($uri . ' cannot be written (not a file)'); } // Open file and write contents $f = new File($uri); // Check if VersionControl is activated if (($prop = $this->propStorage->getProperty($filename, 'D:version')) !== NULL) { $container = $prop->value; $newVersion = WebdavVersionUtil::getNextVersion($container->getLatestVersion(), $f); $container->addVersion($newVersion); // Re-Add modified container to property $prop->value = $container; // Save property $this->propStorage->setProperty($filename, $prop); // Now, copy the "old" file to versions directory $this->backup($filename, '../versions/' . dirname($filename) . '/' . $newVersion->getVersionName()); } try { $new = !$f->exists(); $f->open(FILE_MODE_WRITE); $f->write($data); $f->close(); } catch (IOException $e) { throw new OperationFailedException($filename . ' cannot be written ' . $e->toString()); } // Set the resourcetype on first put if (($prop = $this->propStorage->getProperty($filename, 'D:resourcetype')) == NULL) { // Set ResourceType with($p = new WebdavProperty('resourcetype', $resourcetype)); $p->setNameSpaceName('DAV:'); $p->setNameSpacePrefix('D:'); $this->propStorage->setProperty($filename, $p); } return $new; }
/** * Add Well Known Properties * */ protected function _calcProperties() { $etag = md5($this->href); $etag = sprintf('%s-%s-%s', substr($etag, 0, 7), substr($etag, 7, 4), substr($etag, 11, 8)); foreach (array('creationdate' => array('value' => $this->creationDate, 'ns' => 'DAV:'), 'getlastmodified' => array('value' => $this->modifiedDate, 'ns' => 'DAV:'), 'getcontentlength' => array('value' => $this->contentLength, 'ns' => 'DAV:'), 'getcontenttype' => array('value' => $this->contentType, 'ns' => 'DAV:'), 'isfolder' => array('value' => WEBDAV_COLLECTION == $this->resourceType, 'ns' => 'DAV:'), 'executable' => array('value' => WEBDAV_COLLECTION != $this->resourceType ? FALSE : NULL, 'ns' => 'http://apache.org/dav/props/'), 'displayname' => array('value' => basename($this->href), 'ns' => 'DAV:'), 'nautilus-treat-as-directory' => array('value' => WEBDAV_COLLECTION == $this->resourceType, 'ns' => 'http://services.eazel.com/namespaces'), 'getlastmodified' => array('value' => $this->modifiedDate, 'ns' => 'DAV:'), 'getetag' => array('value' => WEBDAV_COLLECTION != $this->resourceType ? $etag : NULL, 'ns' => 'DAV:')) as $name => $propDef) { if ($propDef['value'] === NULL) { continue; } $p = new WebdavProperty($name, $propDef['value']); $p->setNamespaceName($propDef['ns']); $p->setProtected(TRUE); $this->addProperty($p); } }
/** * Start Version-Control of file * * @param string filename * @return bool * @throws lang.ElementNotFoundException */ public function VersionControl($path, $version) { $props = array(); // Set versions as properties with($p = new WebdavProperty('version', new WebdavVersionsContainer($version))); $p->setNameSpaceName('DAV:'); $p->setNameSpacePrefix('D:'); $props[$p->getNameSpacePrefix() . $p->getName()] = $p; // Set checked-in property with($p = new WebdavProperty('checked-in', '1.0')); $p->setNameSpaceName('DAV:'); $p->setNameSpacePrefix('D:'); $props[$p->getNameSpacePrefix() . $p->getName()] = $p; $this->propStorage->setProperties($path, $props); // Copy file to versions collection $this->backup($path, $version->getHref()); return TRUE; }