Permalink
Browse files

Fix various language issues: lang switching, minisite lang parameter …

…(--fr), cached metadata with localized string (moved in node.info.nocache hook)
  • Loading branch information...
1 parent a03ced6 commit 0a51b15079790985f1c7defc768fc7ec56c21e47 @cdujeu cdujeu committed Jun 28, 2016
@@ -96,6 +96,8 @@ public static function handleRequest(ServerRequestInterface &$requestInterface,
LocaleService::setLanguage($ctx->getUser()->getPref("lang"));
} else if(isSet($requestInterface->getCookieParams()["AJXP_lang"])) {
LocaleService::setLanguage($requestInterface->getCookieParams()["AJXP_lang"]);
+ } else if(SessionService::getLanguage() !== null){
+ LocaleService::setLanguage(SessionService::getLanguage());
}
if(UsersService::usersEnabled() && ApplicationState::detectApplicationFirstRun()){
@@ -76,7 +76,11 @@ public static function setLanguage($lang)
{
$inst = self::getInstance();
if (array_key_exists($lang, $inst->cache["AVAILABLE_LANG"])) {
+ if($lang !== $inst->currentLanguage && isSet($inst->cache["MESSAGES"])){
+ $inst->cache["MESSAGES"] = null;
+ }
$inst->currentLanguage = $lang;
+ SessionService::setLanguage($lang);
}
}
@@ -30,18 +30,34 @@
define('PYDIO_SESSION_NAME', 'AjaXplorer');
define('PYDIO_SESSION_QUERY_PARAM', 'ajxp_sessid');
+/**
+ * Class SessionService
+ * @package Pydio\Core\Services
+ */
class SessionService implements RepositoriesCache
{
private static $sessionName = PYDIO_SESSION_NAME;
+ /**
+ * @param $sessionName
+ */
public static function setSessionName($sessionName){
self::$sessionName = $sessionName;
}
+ /**
+ * @return string
+ */
public static function getSessionName(){
return self::$sessionName;
}
+ /**
+ * @param ServerRequestInterface $request
+ * @param ResponseInterface $response
+ * @param callable|null $next
+ * @return mixed|ResponseInterface
+ */
public static function handleRequest(ServerRequestInterface &$request, ResponseInterface $response, callable $next = null){
$getParams = $request->getQueryParams();
@@ -92,22 +108,34 @@ public static function checkPendingRepository($ctxUser){
}
}
+ /**
+ * @return null
+ */
public static function getSessionRepositoryId(){
return isSet($_SESSION["REPO_ID"]) ? $_SESSION["REPO_ID"] : null;
}
+ /**
+ * @param $repoId
+ */
public static function saveRepositoryId($repoId){
$_SESSION["REPO_ID"] = $repoId;
}
+ /**
+ * @param $repoId
+ */
public static function switchSessionRepositoriId($repoId){
if(isSet($_SESSION["REPO_ID"])){
$_SESSION["PREVIOUS_REPO_ID"] = $_SESSION["REPO_ID"];
}
$_SESSION["REPO_ID"] = $repoId;
}
+ /**
+ * @return null
+ */
public static function getPreviousRepositoryId(){
return isSet($_SESSION["PREVIOUS_REPO_ID"]) ? $_SESSION["PREVIOUS_REPO_ID"] : null;
}
@@ -147,17 +175,44 @@ public static function invalidateLoadedRepositories()
}
}
+ /**
+ * @param $repositoryId
+ * @return null
+ */
public static function getContextCharset($repositoryId)
{
if (isSet($_SESSION["AJXP_CHARSET"])) return $_SESSION["AJXP_CHARSET"];
return null;
}
+ /**
+ * @param $repositoryId
+ * @param $value
+ */
public static function setContextCharset($repositoryId, $value)
{
if (ConfService::$useSession) {
$_SESSION["AJXP_CHARSET"] = $value;
}
}
+
+ /**
+ * @param string $lang
+ */
+ public static function setLanguage($lang){
+ if(ConfService::$useSession){
+ $_SESSION["AJXP_LANG"] = $lang;
+ }
+ }
+
+ /**
+ * @return string|null
+ */
+ public static function getLanguage(){
+ if(isSet($_SESSION["AJXP_LANG"])){
+ return $_SESSION["AJXP_LANG"];
+ }
+ return null;
+ }
}
@@ -1533,15 +1533,14 @@ public function parseLsOptions($optionString)
}
/**
+ * Update node metadata with core FS metadata.
* @param \Pydio\Access\Core\Model\AJXP_Node $ajxpNode
* @param bool $parentNode
* @param bool $details
* @return void
*/
public function loadNodeInfo(&$ajxpNode, $parentNode = false, $details = false)
{
- $mess = LocaleService::getMessages();
-
$nodeName = basename($ajxpNode->getPath());
$metaData = $ajxpNode->metadata;
if (!isSet($metaData["is_file"])) {
@@ -1555,21 +1554,20 @@ public function loadNodeInfo(&$ajxpNode, $parentNode = false, $details = false)
if (RecycleBinManager::recycleEnabled() && $ajxpNode->getPath() == RecycleBinManager::getRelativeRecycle()) {
$recycleIcon = ($this->countChildren($ajxpNode, false, true)>0?"trashcan_full.png":"trashcan.png");
$metaData["icon"] = $recycleIcon;
- $metaData["mimestring"] = $mess[122];
- $ajxpNode->setLabel($mess[122]);
+ $metaData["mimestring_id"] = 122;
+ //$ajxpNode->setLabel($mess[122]);
$metaData["ajxp_mime"] = "ajxp_recycle";
} else {
$mimeData = StatHelper::getMimeInfo($ajxpNode, !$isLeaf);
- $metaData["mimestring_id"] = $mimeData[0]; //AJXP_Utils::mimetype($ajxpNode->getUrl(), "type", !$isLeaf);
- $metaData["icon"] = $mimeData[1]; //AJXP_Utils::mimetype($nodeName, "image", !$isLeaf);
+ $metaData["mimestring_id"] = $mimeData[0];
+ $metaData["icon"] = $mimeData[1];
if ($metaData["icon"] == "folder.png") {
$metaData["openicon"] = "folder_open.png";
}
if (!$isLeaf) {
$metaData["ajxp_mime"] = "ajxp_folder";
}
}
- //if ($lsOptions["l"]) {
$metaData["file_group"] = @filegroup($ajxpNode->getUrl()) || "unknown";
$metaData["file_owner"] = @fileowner($ajxpNode->getUrl()) || "unknown";
@@ -1586,12 +1584,12 @@ public function loadNodeInfo(&$ajxpNode, $parentNode = false, $details = false)
$metaData["file_perms"] = $fPerms;
$datemodif = $this->date_modif($ajxpNode->getUrl());
$metaData["ajxp_modiftime"] = ($datemodif ? $datemodif : "0");
- $metaData["ajxp_description"] =$metaData["ajxp_relativetime"] = $mess[4]." ". StatHelper::relativeDate($datemodif, $mess);
+ //$metaData["ajxp_description"] =$metaData["ajxp_relativetime"] = $mess[4]." ". StatHelper::relativeDate($datemodif, $mess);
$metaData["bytesize"] = 0;
if ($isLeaf) {
$metaData["bytesize"] = filesize($ajxpNode->getUrl());
}
- $metaData["filesize"] = StatHelper::roundSize($metaData["bytesize"]);
+ //$metaData["filesize"] = StatHelper::roundSize($metaData["bytesize"]);
if (StatHelper::isBrowsableArchive($nodeName)) {
$metaData["ajxp_mime"] = "ajxp_browsable_archive";
}
@@ -1611,6 +1609,42 @@ public function loadNodeInfo(&$ajxpNode, $parentNode = false, $details = false)
}
/**
+ * Update nodes metadata with localized info (will NOT be cached)
+ * Hooked to node.info.nocache
+ * @param AJXP_Node $ajxpNode
+ * @param bool $parentNode
+ * @param bool $details
+ */
+ public function localizeNodeInfo(&$ajxpNode, $parentNode = false, $details = false){
+
+ $messages = LocaleService::getMessages();
+ $localMeta = [];
+
+ // Recompute "Modifed on ... " string
+ $currentMeta = $ajxpNode->getNodeInfoMeta();
+ if(!empty($currentMeta["ajxp_modiftime"])){
+ $dateModif = $currentMeta["ajxp_modiftime"];
+ $localMeta["ajxp_description"] = $localMeta["ajxp_relativetime"] = $messages[4]." ". StatHelper::relativeDate($dateModif, $messages);
+ }
+
+ // Recompute human readable size
+ if(!empty($currentMeta["bytesize"])){
+ $localMeta["filesize"] = StatHelper::roundSize($currentMeta["bytesize"]);
+ }
+
+ // Update Recycle Bin label
+ if ($currentMeta["ajxp_mime"] === "ajxp_recycle"){
+ $ajxpNode->setLabel($messages[122]);
+ }
+
+ // Now remerge in node
+ if(count($localMeta)){
+ $ajxpNode->mergeMetadata($localMeta);
+ }
+
+ }
+
+ /**
* @param array|UploadedFileInterface $uploadData Php-upload array
* @param String $destination Full path to destination file, including stream data
* @param array $messages Application messages table
@@ -36,6 +36,7 @@
<external_file filename="plugins/access.fs/fsActions.xml" include="client_configs/*" exclude=""/>
<hooks>
<serverCallback hookName="node.info" methodName="loadNodeInfo"/>
+ <serverCallback hookName="node.info.nocache" methodName="localizeNodeInfo"/>
</hooks>
</registry_contributions>
<class_stream_wrapper filename="plugins/access.fs/FsAccessWrapper.php" classname="Pydio\Access\Driver\StreamProvider\FS\FsAccessWrapper" protocol="ajxp.fs"/>
@@ -1328,10 +1328,10 @@ public static function loadMinisite($data, $hash = '', $error = null)
*/
public static function loadShareByHash($hash){
Logger::debug(__CLASS__, __FUNCTION__, "Do something");
- PluginsService::getInstance()->initActivePlugins();
if(isSet($_GET["lang"])){
LocaleService::setLanguage($_GET["lang"]);
}
+ PluginsService::getInstance()->initActivePlugins();
$shareCenter = self::getShareCenter(Context::emptyContext());
$data = $shareCenter->getShareStore()->loadShare($hash);
$mess = LocaleService::getMessages();
@@ -545,7 +545,7 @@ public function loadNodeInfo($forceRefresh = false, $contextNode = false, $detai
}
}
Controller::applyHook("node.info.start", [&$this, $contextNode, $details, $forceRefresh]);
- if($this->nodeInfoLoaded && !$forceRefresh && isSet($this->_metadata["ajxp_mime"])){
+ if($this->nodeInfoLoaded && !$forceRefresh && (isSet($this->_metadata["ajxp_mime"]) || isSet($this->_metadata["mimestring_id"]))){
Controller::applyHook("node.info.nocache", [&$this, $contextNode, $details, $forceRefresh]);
return;
}
@@ -832,6 +832,12 @@ public function switchAction(ServerRequestInterface $requestInterface, ResponseI
$userObject->recomputeMergedRole();
if ($action == "custom_data_edit") {
AuthService::updateUser($userObject);
+ $crtLang = LocaleService::getLanguage();
+ $newLang = $userObject->getPersonalRole()->filterParameterValue("core.conf", "lang", AJXP_REPO_SCOPE_ALL, $crtLang);
+ if($newLang !== $crtLang){
+ LocaleService::setLanguage($newLang);
+ $mess = LocaleService::getMessages(true);
+ }
}
}

0 comments on commit 0a51b15

Please sign in to comment.