Permalink
Browse files

Start reworking utf-8 management.

  • Loading branch information...
1 parent eaad3c7 commit ea602e4008089cc01706349ab9ea084099072b23 @cdujeu cdujeu committed Sep 6, 2016
@@ -166,7 +166,7 @@ protected function repositoryToXML($repoObject, $isActive, $exposed, $streams, $
}
}
$clientSettings = (!$isActive ? "" : $this->repositoryClientSettings($repoObject, $ctx));
- return "<repo access_type=\"".$repoObject->getAccessType()."\" id=\"".$repoId."\"$statusString $streamString $slugString $isSharedString $roleString><label>".TextEncoder::toUTF8(StringHelper::xmlEntities($repoObject->getDisplay()))."</label>".$descTag.$clientSettings."</repo>";
+ return "<repo access_type=\"".$repoObject->getAccessType()."\" id=\"".$repoId."\"$statusString $streamString $slugString $isSharedString $roleString><label>".StringHelper::xmlEntities($repoObject->getDisplay())."</label>".$descTag.$clientSettings."</repo>";
}
@@ -152,7 +152,7 @@ public static function magicDequote($text)
*/
public static function fromPostedFileName($filesystemElement)
{
- return TextEncoder::fromUTF8(TextEncoder::magicDequote($filesystemElement));
+ return TextEncoder::magicDequote($filesystemElement);
}
/**
@@ -216,7 +216,7 @@ public static function sanitize($s, $level = InputFilter::SANITIZE_HTML, $expand
*/
public static function decodeSecureMagic($data, $sanitizeLevel = InputFilter::SANITIZE_HTML)
{
- return TextEncoder::fromUTF8(InputFilter::sanitize(InputFilter::securePath($data), $sanitizeLevel));
+ return InputFilter::sanitize(InputFilter::securePath($data), $sanitizeLevel);
}
/**
@@ -100,7 +100,7 @@ public function repositoriesActions(ServerRequestInterface $requestInterface, Re
foreach ($repositories as $repo) {
if(!$repo->isTemplate()) continue;
$repoId = $repo->getUniqueId();
- $repoLabel = TextEncoder::toUTF8($repo->getDisplay());
+ $repoLabel = $repo->getDisplay();
$repoType = $repo->getAccessType();
$buffer .= "<template repository_id=\"$repoId\" repository_label=\"$repoLabel\" repository_type=\"$repoType\">";
foreach ($repo->getOptionsDefined() as $optionName) {
@@ -847,7 +847,7 @@ protected function serializeRepositoryToXML(ContextInterface $ctx, $repository,
if (is_bool($option)) {
$option = ($option?"true":"false");
}
- $buffer .= " $name=\"".TextEncoder::toUTF8(StringHelper::xmlEntities($option))."\" ";
+ $buffer .= " $name=\"".StringHelper::xmlEntities($option, true)."\" ";
} else if (is_array($option)) {
$nested[] = $option;
}
@@ -253,18 +253,18 @@ public function rolesActions(ServerRequestInterface $requestInterface, ResponseI
continue;
}
$repoDetailed[$repositoryId] = array(
- "label" => TextEncoder::toUTF8($repositoryObject->getDisplay()),
+ "label" => $repositoryObject->getDisplay(),
"driver" => $repositoryObject->getAccessType(),
"scope" => $repositoryObject->securityScope(),
"meta" => $meta
);
if(array_key_exists($repositoryId, $sharedRepos)){
- $sharedRepos[$repositoryId] = TextEncoder::toUTF8($repositoryObject->getDisplay());
+ $sharedRepos[$repositoryId] = $repositoryObject->getDisplay();
$repoParentLabel = $repoParentId = $repositoryObject->getParentId();
$repoOwnerId = $repositoryObject->getOwner();
if(isSet($allReps[$repoParentId])){
- $repoParentLabel = TextEncoder::toUTF8($allReps[$repoParentId]->getDisplay());
+ $repoParentLabel = $allReps[$repoParentId]->getDisplay();
}
$repoOwnerLabel = UsersService::getUserPersonalParameter("USER_DISPLAY_NAME", $repoOwnerId, "core.conf", $repoOwnerId);
$repoDetailed[$repositoryId]["share"] = array(
@@ -274,7 +274,7 @@ public function rolesActions(ServerRequestInterface $requestInterface, ResponseI
"parent_repository_label" => $repoParentLabel
);
}else{
- $repos[$repositoryId] = TextEncoder::toUTF8($repositoryObject->getDisplay());
+ $repos[$repositoryId] = $repositoryObject->getDisplay();
}
}
@@ -29,6 +29,7 @@
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\UploadedFileInterface;
use Pydio\Access\Core\AbstractAccessDriver;
+use Pydio\Access\Core\EncodingWrapper;
use Pydio\Access\Core\MetaStreamWrapper;
use Pydio\Access\Core\Model\AJXP_Node;
use Pydio\Access\Core\IAjxpWrapperProvider;
@@ -111,6 +112,8 @@ protected function initRepository(ContextInterface $contextInterface)
$chmod = $repository->getContextOption($contextInterface, "CHMOD_VALUE");
$this->urlBase = $contextInterface->getUrlBase();
+ //$encodingWrapper = new EncodingWrapper("UTF-8");
+ MetaStreamWrapper::appendMetaWrapper("pydio.encoding", "Pydio\\Access\\Core\\EncodingWrapper");
if ($create == true) {
if(!is_dir($path)) @mkdir($path, 0755, true);
@@ -332,13 +335,12 @@ public function createResourceAction(ServerRequestInterface &$request, ResponseI
throw new PydioException("Empty resource");
}
$path = $selection->getUniqueFile();
- $notDecodedPath = TextEncoder::toUTF8($path);
$params = $request->getParsedBody();
$newAction = null;
$newVars = [];
if(isSet($params["copy_source"])){
- $newVars["dest"] = PathUtils::forwardSlashDirname($notDecodedPath);
- $newVars["targetBaseName"] = PathUtils::forwardSlashBasename($notDecodedPath);
+ $newVars["dest"] = PathUtils::forwardSlashDirname($path);
+ $newVars["targetBaseName"] = PathUtils::forwardSlashBasename($path);
$sourceParts = explode("/", trim($params["copy_source"], "/"));
$sourceRepo = array_shift($sourceParts);
@@ -358,7 +360,7 @@ public function createResourceAction(ServerRequestInterface &$request, ResponseI
if(substr_compare($qPath, "/", strlen($qPath)-1, 1) === 0){
// Ends with slash => mkdir
$newAction = "mkdir";
- $newVars["file"] = $notDecodedPath;
+ $newVars["file"] = $path;
if(!empty($params["override"])) {
$newVars["ignore_exists"] = $params["override"];
}
@@ -367,7 +369,7 @@ public function createResourceAction(ServerRequestInterface &$request, ResponseI
}
}else{
$newAction = "mkfile";
- $newVars["node"] = $notDecodedPath;
+ $newVars["node"] = $path;
if(!empty($params["content"])) {
$newVars["content"] = $params["content"];
}
@@ -416,7 +418,7 @@ public function uploadAction(ServerRequestInterface &$request, ResponseInterface
$this->logDebug("Upload inside", ["destination"=>$this->addSlugToPath($destNode->getUrl())]);
if (!$this->isWriteable($destNode)) {
$errorCode = 412;
- $errorMessage = "$mess[38] ".TextEncoder::toUTF8($dir)." $mess[99].";
+ $errorMessage = "$mess[38] ".$dir." $mess[99].";
$this->logDebug("Upload error 412", ["destination"=>$this->addSlugToPath($destination)]);
$this->writeUploadError($request, $errorMessage, $errorCode);
return;
@@ -442,7 +444,7 @@ public function uploadAction(ServerRequestInterface &$request, ResponseInterface
// FIND PROPER FILE NAME / FILTER IF NECESSARY
$userfile_name= InputFilter::sanitize(TextEncoder::fromPostedFileName($uploadedFile->getClientFileName()), InputFilter::SANITIZE_FILENAME);
if (isSet($httpVars["urlencoded_filename"])) {
- $userfile_name = InputFilter::sanitize(TextEncoder::fromUTF8(urldecode($httpVars["urlencoded_filename"])), InputFilter::SANITIZE_FILENAME);
+ $userfile_name = InputFilter::sanitize(urldecode($httpVars["urlencoded_filename"]), InputFilter::SANITIZE_FILENAME);
}
$userfile_name = substr($userfile_name, 0, ConfService::getContextConf($ctx, "NODENAME_MAX_LENGTH"));
$this->logDebug("User filename ".$userfile_name);
@@ -510,7 +512,7 @@ public function uploadAction(ServerRequestInterface &$request, ResponseInterface
// PARTIAL UPLOAD - PART II: APPEND DATA TO EXISTING PART
if (isSet($httpVars["appendto_urlencoded_part"])) {
- $appendTo = InputFilter::sanitize(TextEncoder::fromUTF8(urldecode($httpVars["appendto_urlencoded_part"])), InputFilter::SANITIZE_FILENAME);
+ $appendTo = InputFilter::sanitize(urldecode($httpVars["appendto_urlencoded_part"]), InputFilter::SANITIZE_FILENAME);
if(isSet($httpVars["partial_upload"]) && $httpVars["partial_upload"] == 'true'){
$originalAppendTo = $appendTo;
$appendTo .= ".dlpart";
@@ -562,7 +564,7 @@ protected function uploadPostProcess(&$request, $createdNode, $partialUpload = f
$this->changeMode($createdNode->getUrl(),["chmod" => $chmodValue]);
clearstatcache(true, $createdNode->getUrl());
$createdNode->loadNodeInfo(true);
- $logFile = $this->addSlugToPath(TextEncoder::fromUTF8($createdNode->getParent()->getPath()))."/".$createdNode->getLabel();
+ $logFile = $this->addSlugToPath($createdNode->getParent()->getPath())."/".$createdNode->getLabel();
$this->logInfo("Upload File", ["file"=>$logFile, "files"=> $logFile]);
if($partialUpload){
@@ -924,7 +926,7 @@ public function switchAction(ServerRequestInterface &$request, ResponseInterface
$logMessage = new UserMessage(join("\n", $logMessages));
}
if($errorMessage) {
- throw new PydioException(TextEncoder::toUTF8($errorMessage));
+ throw new PydioException($errorMessage);
}
$this->logInfo("Delete", ["files"=>$this->addSlugToPath($selection)]);
$nodesDiffs->remove($selection->getFiles());
@@ -964,7 +966,7 @@ public function switchAction(ServerRequestInterface &$request, ResponseInterface
$logMessage = new UserMessage(join("\n", $logMessages));
}
if($errorMessage) {
- throw new PydioException(TextEncoder::toUTF8($errorMessage));
+ throw new PydioException($errorMessage);
}
$this->logInfo("Delete", ["files"=>$this->addSlugToPath($selection)]);
$nodesDiffs->remove($selection->getFiles());
@@ -1033,16 +1035,16 @@ public function switchAction(ServerRequestInterface &$request, ResponseInterface
}
if (count($error)) {
- if(!empty($taskId)) TaskService::getInstance()->updateTaskStatus($taskId, Task::STATUS_FAILED, "Error while copy/move: ".TextEncoder::toUTF8(join("\n", $error)));
- throw new PydioException(TextEncoder::toUTF8(join("\n", $error)));
+ if(!empty($taskId)) TaskService::getInstance()->updateTaskStatus($taskId, Task::STATUS_FAILED, "Error while copy/move: ".join("\n", $error));
+ throw new PydioException(join("\n", $error));
} else {
if (isSet($httpVars["force_copy_delete"])) {
$errorMessage = $this->delete($selection, $logMessages, $taskId);
if($errorMessage) {
if(!empty($taskId)) {
- TaskService::getInstance()->updateTaskStatus($taskId, Task::STATUS_FAILED, "Error while deleting data: ".TextEncoder::toUTF8($errorMessage));
+ TaskService::getInstance()->updateTaskStatus($taskId, Task::STATUS_FAILED, "Error while deleting data: ".$errorMessage);
}
- throw new PydioException(TextEncoder::toUTF8($errorMessage));
+ throw new PydioException($errorMessage);
}
$this->logInfo("Copy/Delete", ["files"=>$this->addSlugToPath($selection), "destination" => $this->addSlugToPath($destPath)]);
} else {
@@ -1103,7 +1105,7 @@ public function switchAction(ServerRequestInterface &$request, ResponseInterface
}
$renamedNode = $this->rename($originalNode, $destNode, $filename_new);
- $logMessage = new UserMessage(TextEncoder::toUTF8($originalNode->getLabel())." $mess[41] ".TextEncoder::toUTF8($renamedNode->getLabel()));
+ $logMessage = new UserMessage($originalNode->getLabel()." $mess[41] ".$renamedNode->getLabel());
$nodesDiffs->update($renamedNode, $originalNode->getPath());
$this->logInfo("Rename", [
"files" => $this->addSlugToPath($originalNode->getUrl()),
@@ -1155,8 +1157,8 @@ public function switchAction(ServerRequestInterface &$request, ResponseInterface
if(empty($newNode)){
continue;
}
- $messtmp.="$mess[38] ".TextEncoder::toUTF8($basename)." $mess[39] ";
- if ($parentDir=="") {$messtmp.="/";} else {$messtmp.= TextEncoder::toUTF8($parentDir);}
+ $messtmp.="$mess[38] ".$basename." $mess[39] ";
+ if ($parentDir=="") {$messtmp.="/";} else {$messtmp.= $parentDir;}
$messages[] = $messtmp;
$nodesDiffs->add($newNode);
$this->logInfo("Create Dir", ["dir"=>$this->addSlugToPath($parentDir)."/".$basename, "files"=>$this->addSlugToPath($parentDir)."/".$basename]);
@@ -1509,7 +1511,7 @@ public function switchAction(ServerRequestInterface &$request, ResponseInterface
continue;
}
$newBody = [
- "dir" => TextEncoder::toUTF8($nodeDir->getPath()),
+ "dir" => $nodeDir->getPath(),
"options"=> $httpVars["options"],
"recursive" => "true",
"max_depth"=> $max_depth,
@@ -2228,14 +2230,14 @@ public function delete(UserSelection $selection, &$logMessages, $taskId = null)
$filePath = $selectedNode->getPath();
if (!file_exists($fileUrl)) {
- $logMessages[]=$mess[100]." ".TextEncoder::toUTF8($filePath);
+ $logMessages[]=$mess[100]." ".$filePath;
continue;
}
$this->deldir($fileUrl, $repoData, $taskId);
if ($selectedNode->isLeaf()) {
- $logMessages[]="$mess[38] ".TextEncoder::toUTF8($filePath)." $mess[44].";
+ $logMessages[]="$mess[38] ".$filePath." $mess[44].";
} else {
- $logMessages[]="$mess[34] ".TextEncoder::toUTF8($filePath)." $mess[44].";
+ $logMessages[]="$mess[34] ".$filePath." $mess[44].";
}
Controller::applyHook("node.change", [$selectedNode]);
}
@@ -221,8 +221,8 @@ public function client ($params, $purl)
while ($line = fgets ($output, 4096)) {
if (PHP_OS == "WIN32" || PHP_OS == "WINNT" || PHP_OS == "Windows") {
- $line = \Pydio\Core\Utils\TextEncoder::fromUTF8($line);
- }
+ //$line = \Pydio\Core\Utils\TextEncoder::fromUTF8($line);
+ }
list ($tag, $regs, $i) = array ('skip', array (), array ());
reset ($regexp);
@@ -1412,7 +1412,7 @@ public function filterHttpVarsForLeafPath(&$httpVars, $userSelection){
}
if(!isSet($httpVars["repo_label"])){
$first = $userSelection->getUniqueNode();
- $httpVars["repo_label"] = TextEncoder::toUTF8($first->getLabel());
+ $httpVars["repo_label"] = $first->getLabel();
}
}
@@ -1430,7 +1430,7 @@ public function filterHttpVarsFromUniqueNode(&$httpVars, $ajxpNode){
$httpVars["nodes"] = array("/");
}
if(!isSet($httpVars["repo_label"])){
- $httpVars["repo_label"] = TextEncoder::toUTF8($ajxpNode->getLabel());
+ $httpVars["repo_label"] = $ajxpNode->getLabel();
}
}
@@ -596,8 +596,8 @@ public function moveSharesFromMeta($shares, $operation="move", $oldNode, $newNod
}
if(isSet($repo)){
- $oldNodeLabel = TextEncoder::toUTF8($oldNode->getLabel());
- $newNodeLabel = TextEncoder::toUTF8($newNode->getLabel());
+ $oldNodeLabel = $oldNode->getLabel();
+ $newNodeLabel = $newNode->getLabel();
if($newNode != null && $newNodeLabel != $oldNodeLabel && $repo->getDisplay() == $oldNodeLabel){
$repo->setDisplay($newNodeLabel);
}
@@ -614,8 +614,8 @@ public function moveSharesFromMeta($shares, $operation="move", $oldNode, $newNod
$save = true;
}else if(!empty($path)){
- $oldNodePath = TextEncoder::toUTF8($oldNode->getPath());
- $newNodePath = TextEncoder::toUTF8($newNode->getPath());
+ $oldNodePath = $oldNode->getPath();
+ $newNodePath = $newNode->getPath();
$path = preg_replace("#".preg_quote($oldNodePath, "#")."$#", $newNodePath, $path);
$repo->addOption("PATH", $path);
@@ -636,8 +636,8 @@ public function moveSharesFromMeta($shares, $operation="move", $oldNode, $newNod
} else {
if(isset($publicLink) && is_array($publicLink) && isSet($publicLink["FILE_PATH"])){
- $oldNodePath = TextEncoder::toUTF8($oldNode->getPath());
- $newNodePath = TextEncoder::toUTF8($newNode->getPath());
+ $oldNodePath = $oldNode->getPath();
+ $newNodePath = $newNode->getPath();
$publicLink["FILE_PATH"] = str_replace($oldNodePath, $newNodePath, $publicLink["FILE_PATH"]);
$this->deleteShare("file", $id);
$this->storeShare($newNode->getRepositoryId(), $publicLink, "file", $id);
Oops, something went wrong.

0 comments on commit ea602e4

Please sign in to comment.