/**
  * Gets the file information of the specified file in the entered language
  *
  * @param   string  $userLang           Language used by the current user
  * @param   string  $defaultLang        Default language defined in the
  *          application settings
  * @param   string  $basePath           Base path for the file in the file
  *          system
  * @param   string  $fileExt            Extension of the file; it can be:
  *          'txt' or 'pdf'
  * @param   bool    $getContent         Whether or not to get the file
  *          contents; only used for the txt files
  * @param   int     $maxFileSize        Maximum size of the file in
  *          megabytes; only used for the txt files
  * @param   bool    $getFallbackLang    Whether or not to get files for fall
  *          back languages in case that the current and the default
  *          languages aren't found
  *
  * @return array    Array with the file information. It has this format:
  *                  [
  *                      'exists'  => <does_the_file_exist>,
  *                      'lang'    => <file_language_code>,
  *                      'name'    => <file_name>,
  *                      'path'    => <file_location_in_the_file_system>,
  *                      'url'     => <url_to_file_in_web_browser>,
  *                      'content' => <contents_txt_file>,
  *                      'error'   => <error_message>,
  *                  ],
  */
 public static function getFile($userLang, $defaultLang, $basePath, $fileExt, $getContent = false, $maxFileSize = 2, $getFallbackLang = true)
 {
     $fileInfo = array();
     $appId = Application::APP_ID;
     $fileName = Application::FILE_PREFFIX . '_' . $userLang . '.' . $fileExt;
     $filePath = $basePath . DIRECTORY_SEPARATOR . $fileName;
     $fileInfo['exists'] = file_exists($filePath);
     $fileInfo['lang'] = $userLang;
     $langFallbacks = Utils::getFallbackLang($userLang);
     $errorMsg = '';
     $userLangFile = $filePath;
     if (!$fileInfo['exists']) {
         $errorMsg = \OCP\Util::getL10N($appId)->t('%s doesn\'t exist.', $userLangFile . '<br/>') . ' ' . \OCP\Util::getL10N($appId)->t('Please contact the webmaster');
         $languages = array();
         if ($getFallbackLang) {
             $languages = array_merge($languages, $langFallbacks);
         }
         if ($userLang !== $defaultLang) {
             $languages[] = $defaultLang;
         }
         foreach ($languages as $langCode) {
             $fileName = Application::FILE_PREFFIX . '_' . $langCode . '.' . $fileExt;
             $filePath = $basePath . DIRECTORY_SEPARATOR . $fileName;
             $fileInfo['exists'] = file_exists($filePath);
             if ($fileInfo['exists']) {
                 $fileInfo['lang'] = $langCode;
                 break;
             }
         }
     }
     $fileInfo['path'] = $filePath;
     $fileInfo['url'] = \OC::$server->getURLGenerator()->linkTo($appId, $fileExt . DIRECTORY_SEPARATOR . $fileName);
     $fileInfo['name'] = $fileName;
     $fileInfo['error'] = '';
     if ($getContent && $fileInfo['exists']) {
         $maxBytes = $maxFileSize * 1048576;
         $file_contents = file_get_contents($filePath, false, null, 0, $maxBytes);
         if ($file_contents === false) {
             //You have to use === otherwise the empty string will be
             //evaluated to false
             $message = 'Could not read contents from file:\\n' . $filePath . '\\n\\nMake sure that the file exists and that it is ' . 'readable by the apache user';
             //This ensures that carriage returns appear in a textarea
             $message = Utils::fixCarriageReturns($message);
             \OCP\Util::writeLog($appId, $message, \OCP\Util::FATAL);
             $file_contents = '';
             $fileInfo['error'] = $message;
         }
         $fileInfo['content'] = $file_contents;
     } elseif (!$fileInfo['exists']) {
         if ($userLang !== $defaultLang) {
             $errorMsg = \OCP\Util::getL10N($appId)->t('Neither the file:' . ' %s nor: %s exist', ['<br/>' . $userLangFile . '<br/><br/>', '<br/>' . $filePath . '<br/><br/>']) . '. ' . \OCP\Util::getL10N($appId)->t('Please contact the ' . 'webmaster');
         }
         //This ensures that carriage returns appear in a textarea
         $errorMsg = Utils::fixCarriageReturns($errorMsg);
         $fileInfo['error'] = $errorMsg;
     }
     return $fileInfo;
 }