Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Start reworking utf-8 management.
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Sep 6, 2016
1 parent eaad3c7 commit ea602e4
Show file tree
Hide file tree
Showing 23 changed files with 325 additions and 92 deletions.
2 changes: 1 addition & 1 deletion core/src/core/src/pydio/Core/Serializer/RepositoryXML.php
Expand Up @@ -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>";

}

Expand Down
2 changes: 1 addition & 1 deletion core/src/core/src/pydio/Core/Utils/TextEncoder.php
Expand Up @@ -152,7 +152,7 @@ public static function magicDequote($text)
*/
public static function fromPostedFileName($filesystemElement)
{
return TextEncoder::fromUTF8(TextEncoder::magicDequote($filesystemElement));
return TextEncoder::magicDequote($filesystemElement);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion core/src/core/src/pydio/Core/Utils/Vars/InputFilter.php
Expand Up @@ -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);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/access.ajxp_conf/src/RepositoriesManager.php
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions core/src/plugins/access.ajxp_conf/src/RolesManager.php
Expand Up @@ -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(
Expand All @@ -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();
}

}
Expand Down
46 changes: 24 additions & 22 deletions core/src/plugins/access.fs/FsAccessDriver.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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"];
}
Expand All @@ -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"];
}
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()),
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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]);
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/access.smb/smb.php
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/action.share/src/ShareCenter.php
Expand Up @@ -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();
}

}
Expand All @@ -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();
}
}

Expand Down
12 changes: 6 additions & 6 deletions core/src/plugins/action.share/src/Store/ShareStore.php
Expand Up @@ -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);
}
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit ea602e4

Please sign in to comment.