/** * Get the content of a file */ public function getFile() { $am = AccountManager::getInstance(); if (!$am->isLogged()) { return JsonResponseBuilder::failure(); } $appConf = $am->appConf; $project = $am->project; $FilePath = $this->getRequestVariable('FilePath'); $FileName = $this->getRequestVariable('FileName'); $readOriginal = $this->hasRequestVariable('readOriginal') ? $this->getRequestVariable('readOriginal') : false; $ggTranslate = $this->hasRequestVariable('ggTranslate') ? $this->getRequestVariable('ggTranslate') : false; $skeleton = $this->getRequestVariable('skeleton'); // ExtJs pass false as a string ; fix it if ($readOriginal == "false") { $readOriginal = false; } if ($ggTranslate == "false") { $ggTranslate = false; } if ($skeleton == "false") { $skeleton = false; } // Handle if we want to load a skeleton when we create a new file if ($skeleton) { // Security fix $skeleton = str_replace('..', '', $skeleton); // $skeleton is the ful path of the file // It must start with this : $appConf[$project]['skeletons.folder'] if (!isset($appConf[$project]['skeletons.folder'])) { return false; } if (substr($skeleton, 0, strlen($appConf[$project]['skeletons.folder'])) != $appConf[$project]['skeletons.folder']) { return false; } $return['content'] = $skeleton == '-' ? '' : file_get_contents($skeleton); $return['warn_tab'] = false; $return['warn_encoding'] = false; $return['xmlid'] = ''; return JsonResponseBuilder::success($return); } $t = explode('/', $FilePath); $FileLang = array_shift($t); $FilePath = implode('/', $t); // We must detect the encoding of the file with the first line "xml version="1.0" encoding="utf-8" // If this utf-8, we don't need to use utf8_encode to pass to this app, else, we apply it $file = new File($FileLang, $FilePath . $FileName); // If we want to get the translation from google translate API if ($ggTranslate) { $content = $file->translate(); $return['content'] = $content; $return['warn_tab'] = false; $return['warn_encoding'] = false; $return['xmlid'] = ''; $return['fileModified'] = false; return JsonResponseBuilder::success($return); } $content = $file->read($readOriginal); $encoding = $file->getEncoding($content); $info = $file->getInfo($content); $return = array(); $return['warn_encoding'] = false; if (strtoupper($encoding) == 'UTF-8') { $return['content'] = $content; } else { $return['content'] = iconv($encoding, "UTF-8", $content); // We mark this file to be automatically modified by codemirror only if this file is a lang/ or en/ file. if (RepositoryManager::getInstance()->isValidLanguage($FileLang)) { $return['warn_encoding'] = true; } } if (isset($info['xmlid'])) { $return['xmlid'] = $info['xmlid']; } // Warn if this file contains some tab caracter, we replace it with 4 space if (strstr($return['content'], "\t")) { $return['content'] = str_replace("\t", " ", $return['content']); $return['warn_tab'] = true; } else { $return['warn_tab'] = false; } // We must check if this file isn't own by the current user $return['fileModified'] = $file->isModified(); // We return the rev number too $return['originalRev'] = $info['rev']; return JsonResponseBuilder::success($return); }