コード例 #1
0
 protected function getLanguage()
 {
     $conf = new Config($this->webos);
     if ($this->webos->managers()->get('File')->exists('~/.config/locale.xml')) {
         $conf->load('~/.config/locale.xml');
     }
     if ($conf->exist('language')) {
         $lang = $conf->get('language');
     } else {
         $lang = $this->webos->managers()->get('Translation')->detectLanguage();
         if ($this->webos->getUser()->isConnected()) {
             $conf->set('language', $lang);
             $conf->save('~/.config/locale.xml');
         }
     }
     if ($conf->exist('locale')) {
         $locale = $conf->get('locale');
     } else {
         $locale = $lang;
         if ($this->webos->getUser()->isConnected()) {
             $conf->set('locale', $locale);
             $conf->save('~/.config/locale.xml');
         }
     }
     return array('language' => $lang, 'locale' => $locale);
 }
コード例 #2
0
 /**
  * Afficher l'interface utilisateur (via JavaScript).
  */
 public function run()
 {
     //On detecte la langue du visiteur si elle ne l'est pas
     $conf = new Config($this);
     if ($this->managers()->get('File')->exists('~/.config/locale.xml')) {
         $conf->load('~/.config/locale.xml');
     }
     if ($conf->exist('language')) {
         $this->managers()->get('Translation')->setLanguage($conf->get('language'));
     } else {
         $lang = $this->managers()->get('Translation')->detectLanguage();
         if ($this->user->isConnected()) {
             $conf->set('language', $lang);
             $conf->save('~/.config/locale.xml');
         }
     }
     //On recupere les fichiers JavaScript de base a inclure
     $jsIncludes = $this->_getJsBootFiles();
     ob_start();
     //On inclut le layout (structure HTMl de base)
     require 'boot/includes/layout.php';
     $out = ob_get_contents();
     ob_end_clean();
     //On ajoute le HTML genere a la reponse HTTP
     $this->getHTTPResponse()->addContent($out);
     //On envoie la reponse HTTP
     $this->getHTTPResponse()->send();
 }
コード例 #3
0
 /**
  * Recuperer un parametre de configuration.
  * @param string $path Le chemin vers le fichier de configuration.
  * @param string $index Le parametre de configuration a recuperer.
  * @throws InvalidArgumentException
  */
 protected function get($path, $index)
 {
     $config = new Config($this->webos);
     $config->load($path);
     if (!$config->exist($index)) {
         throw new InvalidArgumentException('Le parametre de configuration "' . $index . '" est introuvable dans "' . $path . '"');
     }
     return array('value' => $config->get($index));
 }
コード例 #4
0
 public function getAvailableSpace($path)
 {
     $cacheFile = '/var/cache/diskusage.json';
     if (empty($this->quotas)) {
         $config = new Config($this->webos);
         $config->load('/etc/quotas.xml');
         $this->quotas['home'] = (int) $config->get('home');
     }
     $usersSizes = null;
     if (count($this->sizes) == 0 && $this->exists($cacheFile)) {
         $usersSizes = json_decode($this->get($cacheFile)->contents(), true);
         if (array_key_exists($this->webos->getUser()->getId(), $usersSizes)) {
             $this->sizes = $usersSizes[$this->webos->getUser()->getId()];
         }
     }
     $paths = array('home' => $this->userDirectory());
     $availableSpace = -1;
     $sizesModified = false;
     foreach ($paths as $name => $dirname) {
         if (strpos($path, $dirname) === 0) {
             if ($this->quotas[$name] == -1) {
                 continue;
             }
             if (!array_key_exists($name, $this->sizes)) {
                 if (!$this->exists($dirname)) {
                     continue;
                 }
                 $dir = $this->get($dirname);
                 if (!$dir->isDir()) {
                     continue;
                 }
                 $this->sizes[$name] = $dir->contentsSize();
                 $sizesModified = true;
             }
             $dirAvailableSpace = $this->quotas[$name] - $this->sizes[$name];
             if ($availableSpace == -1 or $dirAvailableSpace < $availableSpace) {
                 $availableSpace = $dirAvailableSpace;
             }
         }
     }
     if ($sizesModified) {
         if (!$this->exists($cacheFile)) {
             $cacheFile = $this->createFile($cacheFile);
             if (empty($usersSizes)) {
                 $usersSizes = array();
             }
         } else {
             $cacheFile = $this->get($cacheFile);
             if (empty($usersSizes)) {
                 $usersSizes = json_decode($cacheFile->contents(), true);
             }
         }
         $usersSizes[$this->webos->getUser()->getId()] = $this->sizes;
         $cacheFile->setContents(json_encode($usersSizes));
     }
     return $availableSpace;
 }