Example #1
0
 function testIsSubDirectory()
 {
     $result = OC_Helper::isSubDirectory("./data/", "/anotherDirectory/");
     $this->assertFalse($result);
     $result = OC_Helper::isSubDirectory("./data/", "./data/");
     $this->assertTrue($result);
     mkdir("data/TestSubdirectory", 0777);
     $result = OC_Helper::isSubDirectory("data/TestSubdirectory/", "data");
     rmdir("data/TestSubdirectory");
     $this->assertTrue($result);
 }
Example #2
0
File: l10n.php Project: slapia/core
 protected function init()
 {
     if ($this->app === true) {
         return;
     }
     $app = OC_App::cleanAppId($this->app);
     $lang = str_replace(array('\\0', '/', '\\', '..'), '', $this->lang);
     $this->app = true;
     // Find the right language
     if (is_null($lang) || $lang == '') {
         $lang = self::findLanguage($app);
     }
     // Use cache if possible
     if (array_key_exists($app . '::' . $lang, self::$cache)) {
         $this->translations = self::$cache[$app . '::' . $lang]['t'];
     } else {
         $i18nDir = self::findI18nDir($app);
         $transFile = strip_tags($i18nDir) . strip_tags($lang) . '.json';
         // Texts are in $i18ndir
         // (Just no need to define date/time format etc. twice)
         if ((OC_Helper::isSubDirectory($transFile, OC::$SERVERROOT . '/core/l10n/') || OC_Helper::isSubDirectory($transFile, OC::$SERVERROOT . '/lib/l10n/') || OC_Helper::isSubDirectory($transFile, OC::$SERVERROOT . '/settings') || OC_Helper::isSubDirectory($transFile, OC_App::getAppPath($app) . '/l10n/')) && file_exists($transFile)) {
             // load the translations file
             if ($this->load($transFile)) {
                 //merge with translations from theme
                 $theme = \OC::$server->getConfig()->getSystemValue('theme');
                 if (!empty($theme)) {
                     $transFile = OC::$SERVERROOT . '/themes/' . $theme . substr($transFile, strlen(OC::$SERVERROOT));
                     if (file_exists($transFile)) {
                         $this->load($transFile, true);
                     }
                 }
             }
         }
         self::$cache[$app . '::' . $lang]['t'] = $this->translations;
     }
 }
Example #3
0
 public function getL10nFilesForApp($app, $lang)
 {
     $languageFiles = [];
     $i18nDir = $this->findL10nDir($app);
     $transFile = strip_tags($i18nDir) . strip_tags($lang) . '.json';
     if ((\OC_Helper::isSubDirectory($transFile, \OC::$SERVERROOT . '/core/l10n/') || \OC_Helper::isSubDirectory($transFile, \OC::$SERVERROOT . '/lib/l10n/') || \OC_Helper::isSubDirectory($transFile, \OC::$SERVERROOT . '/settings/l10n/') || \OC_Helper::isSubDirectory($transFile, \OC_App::getAppPath($app) . '/l10n/')) && file_exists($transFile)) {
         // load the translations file
         $languageFiles[] = $transFile;
         // merge with translations from theme
         $theme = $this->config->getSystemValue('theme');
         if (!empty($theme)) {
             $transFile = \OC::$SERVERROOT . '/themes/' . $theme . substr($transFile, strlen(\OC::$SERVERROOT));
             if (file_exists($transFile)) {
                 $languageFiles[] = $transFile;
             }
         }
     }
     return $languageFiles;
 }
Example #4
0
 protected function init()
 {
     if ($this->app === true) {
         return;
     }
     $app = OC_App::cleanAppId($this->app);
     $lang = str_replace(array('\\0', '/', '\\', '..'), '', $this->lang);
     $this->app = true;
     // Find the right language
     if (is_null($lang) || $lang == '') {
         $lang = self::findLanguage($app);
     }
     // Use cache if possible
     if (array_key_exists($app . '::' . $lang, self::$cache)) {
         $this->translations = self::$cache[$app . '::' . $lang]['t'];
         $this->localizations = self::$cache[$app . '::' . $lang]['l'];
     } else {
         $i18ndir = self::findI18nDir($app);
         // Localization is in /l10n, Texts are in $i18ndir
         // (Just no need to define date/time format etc. twice)
         if ((OC_Helper::isSubDirectory($i18ndir . $lang . '.php', OC::$SERVERROOT . '/core/l10n/') || OC_Helper::isSubDirectory($i18ndir . $lang . '.php', OC::$SERVERROOT . '/lib/l10n/') || OC_Helper::isSubDirectory($i18ndir . $lang . '.php', OC::$SERVERROOT . '/settings') || OC_Helper::isSubDirectory($i18ndir . $lang . '.php', OC_App::getAppPath($app) . '/l10n/')) && file_exists($i18ndir . $lang . '.php')) {
             // Include the file, save the data from $CONFIG
             $transFile = strip_tags($i18ndir) . strip_tags($lang) . '.php';
             include $transFile;
             if (isset($TRANSLATIONS) && is_array($TRANSLATIONS)) {
                 $this->translations = $TRANSLATIONS;
                 //merge with translations from theme
                 $theme = OC_Config::getValue("theme");
                 if (!is_null($theme)) {
                     $transFile = OC::$SERVERROOT . '/themes/' . $theme . substr($transFile, strlen(OC::$SERVERROOT));
                     if (file_exists($transFile)) {
                         include $transFile;
                         if (isset($TRANSLATIONS) && is_array($TRANSLATIONS)) {
                             $this->translations = array_merge($this->translations, $TRANSLATIONS);
                         }
                     }
                 }
             }
             if (isset($PLURAL_FORMS)) {
                 $this->plural_form_string = $PLURAL_FORMS;
             }
         }
         if (file_exists(OC::$SERVERROOT . '/core/l10n/l10n-' . $lang . '.php') && OC_Helper::isSubDirectory(OC::$SERVERROOT . '/core/l10n/l10n-' . $lang . '.php', OC::$SERVERROOT . '/core/l10n/')) {
             // Include the file, save the data from $CONFIG
             include OC::$SERVERROOT . '/core/l10n/l10n-' . $lang . '.php';
             if (isset($LOCALIZATIONS) && is_array($LOCALIZATIONS)) {
                 $this->localizations = array_merge($this->localizations, $LOCALIZATIONS);
             }
         }
         self::$cache[$app . '::' . $lang]['t'] = $this->translations;
         self::$cache[$app . '::' . $lang]['l'] = $this->localizations;
     }
 }